1

When i serialize my DataTable using json.NET and return as json string in WCF service i have the following data

myJson data :

[{\"Name\":\"Name1\",\"Age\":20},{\"Name\":\"Name2\",\"Age\":23},{\"Name\":\"Name3\",\"Age\":28}]

But it is not bind in jquery chart because of the escape characters. Actually when the above value is write in Console.WriteLine it returns the correct data like below. In Server side also if i use JsonTextReader data getting like below :

[{"Name":"Name1","Age":20},{"Name":"Name2","Age":23},{"Name":"Name3","Age":28}]

So how to chnage the format in Jquery or can i send the data same as second one in wcf?

Kamlesh Arya
  • 4,864
  • 3
  • 21
  • 28
Akhil
  • 1,918
  • 5
  • 30
  • 74

2 Answers2

3

use jQuery.parseJSON() method

var obj = jQuery.parseJSON("[{\"Name\":\"Name1\",\"Age\":20},{\"Name\":\"Name2\",\"Age\":23},{\"Name\":\"Name3\",\"Age\":28}]");

This will create the json object

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Just to add the pure JavaScript answer, you can use JSON.Parse(string to parse) as well as jQuery.parseJSON(string to parse) without needing to load an entire framework.

var jsonData = "[{\"Name\":\"Name1\",\"Age\":20},{\"Name\":\"Name2\",\"Age\":23},{\"Name\":\"Name3\",\"Age\":28}]";

var obj1 = JSON.parse(jsonData);
var obj2 = jQuery.parseJSON(jsonData);

Here's a fiddle

KyleMit
  • 30,350
  • 66
  • 462
  • 664