Reputation: 837
string result="12334,23432,3453455";
I am getting this string through Ajax call but it gives me the following error: "unexpected non-whitespace character after JSON data"
When I remove comma's between strings it works fine .How to handle this?. I want to put value in textarea with comma's after the Ajax call
Upvotes: 0
Views: 3190
Reputation: 101594
Whatever's outputting that isn't doing so in JSON format, but more like CSV.
A few options:
"12334,23432,3453455".split(',')
JSON.parse("["+"12334,23432,3453455"+"]")
(wrap with []
)dataType:'text'
in your $.ajax
call.Options 1-3 of the above would result in [12334,23432,3453455]
as a javascript array of numbers, while Option 4 will simply result in "12334,23432,3453455"
as a string.
BTW, using JSON.NET
, this is what it should result in:
// As an array:
Int32[] ary = new[]{ 12334, 23432, 3453455 };
Console.WriteLine(JsonConvert.SerializeObject(ary));
// [12334,23432,3453455]
// As a string:
String str = "12334,23432,3453455";
Console.WriteLine(JsonConvert.SerializeObject(str));
// "12334,23432,3453455"
Upvotes: 1
Reputation: 2634
Your data has to be parsed by your JSON parser.
If your data is an array
, your string should look like:
"[12334,23432,3453455]"
or should it be astring
:
"\"12334,23432,3453455\""
Upvotes: 0