I tried to detect JSON support with if(JSON.parse) {}
but it doesn't works. Is there any way to detect the JSON support?
相关问题
- 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
Taken from the json most famous implementation https://github.com/douglascrockford/JSON-js/blob/master/json2.js
(I have merged the two
if
:if (!JSON) {
of line 163 andif (typeof JSON.parse !== 'function') {
of line 406.The trick here is that the
var JSON
will get the value of the JSON object of the browser,undefined
if not.Note that in the latest version of the library they changed the code to something like:
(without pre-declaring the
var JSON
)Might not exactly count as an answer to what was asked, but would perhaps parsing the user agent (navigator) and checking for versions you are confident support the parser be a possible alternative?