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?

2
  • If you are getting as string, in javascript use JSON.parse(serverData) Commented Jan 29, 2014 at 12:59
  • possible duplicate of How to parse JSON in JavaScript Commented Jan 29, 2014 at 13:35

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Thanks friend. But how i parse when bind in kendo ui

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.