简体   繁体   English

如何使用jQuery将对象解析为JSON?

[英]How to parse an object to JSON using jQuery?

I know to use eval() to parse JSON to an object, but how do I parse an object to JSON format using JavaScript? 我知道使用eval()将JSON解析为对象,但是如何使用JavaScript将对象解析为JSON格式?

Thanks. 谢谢。

The newer browsers support JSON.stringify . 较新的浏览器支持JSON.stringify You can also download and include it yourself. 您也可以自己下载并包含它。

var json = JSON.stringify(yourObject);

Afaik jQuery does not provide such a method. Afaik jQuery不提供这种方法。

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: 通常,如果您有一个json并想访问其下面的内容,则只需在其上放一个点,例如json的名称为msg,并且希望location参数为:

msg.location msg.location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM