What is the JSON global object?
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
}
精彩评论