2

I know to use eval() to parse JSON to an object, but how do I parse an object to JSON format using JavaScript?

Thanks.

2

2 Answers 2

4

The newer browsers support JSON.stringify. You can also download and include it yourself.

var json = JSON.stringify(yourObject);

Afaik jQuery does not provide such a method.

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

3 Comments

can JSON object easy to parse an json string to an object ?
It's not a simple task and I don't think jquery provides this. JSON is not supported in IE. json.org/json2.js will do what you need with JSON.stringify and JSON.parse. Ext-core has methods called Ext.encode and Ext decode which do the same thing sencha.com/products/core/docs/?class=Ext
@zjm1126: It don't know exactly what you mean, but JSON also provides the JSON.parse method. It is described on the site I linked to.
0

Usually if you have a json and want to access something underneath it you just put a dot, like if the name of your json is msg and you want the location parameter it would be:

msg.location

Comments

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.