开发者

What is the JSON global object?

开发者 https://www.devze.com 2023-02-12 12:38 出处:网络
I\'m reading that the best way to parse JSON in the browser is by usi开发者_运维知识库ng the JSON.parse() method.

I'm reading that the best way to parse JSON in the browser is by usi开发者_运维知识库ng the JSON.parse() method.

Sorry, I've been living under a rock — where the hell did this JSON global object come from? Is it defined in some standard? Is it available in all browsers? When should I use Crockford's json2.js instead?


It is part of ECMAScript 5, and is the Object with the internal class JSON that holds relevant methods (stringify and parse) for processing JSON data.

Use the json2 library in browsers where JSON is not implemented.

You could test for it like this:

if( Object.prototype.toString.call( window.JSON ) !== '[object JSON]' ) {
    // load the library
}
0

精彩评论

暂无评论...
验证码 换一张
取 消