I have seen references to some browsers natively supporting JSON parsing/serialization of objects safely and efficiently via the window.JSON
Object, but details are hard to come by. Can anyone point in the right direction? What are the methods this Object exposes? What browsers is it supported under?
相关问题
- Is there a limit to how many levels you can nest i
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to toggle on Order in ReactJS
- StackExchange API - Deserialize Date in JSON Respo
jQuery-1.7.1.js - 555 line...
The advantage of using json2.js is that it will only install a parser if the browser does not already have one. You can maintain compatibility with older browsers, but use the native JSON parser (which is more secure and faster) if it is available.
Browsers with Native JSON:
G.
[extending musicfreak comment]
If you are using jQuery, use parseJSON
Internally it checks if browser supports .JSON.parse, and (if available) calls native window.JSON.parse.
If not, does parse itself.
For the benefit of anyone who runs into this thread - for an up-to-date, definitive list of browsers that support the JSON object look here.. A brief generic answer - pretty much all browsers that really matter in the year 2013+.
All modern browsers support native JSON encoding/decoding (Internet Explorer 8+, Firefox 3.1+, Safari 4+, and Chrome 3+). Basically,
JSON.parse(str)
will parse the JSON string instr
and return an object, andJSON.stringify(obj)
will return the JSON representation of the objectobj
.More details on the MDN article.