IE gives an error trying to parse JSON

That's it, I'm trying to parse some JSON, and IE gives me an error, but no wonder other browsers are ok with it. Here is my code:

var result = JSON.parse(data.result); var uploadType = result[0].upload_type; var filename = result[0].name; var insert_id = result[0].insert_id; 

I get an error in the first line. Any idea how to make this IE proof?

Thanks!

+4
source share
5 answers

Internet Explorer does not support JSON.parse prior to version 8. Instead, you can use jQuery.parseJSON (as I see, you noted the question).

+13
source

Internet Explorer does not support JSON.parse, it refers to a json2 script, and you get the same functionality.

+1
source

You did not specify a version of IE, but if you use IE8 or earlier, it does not support the JSON object natively.

You will need a third-party library for the polyfill of this function.

jQuery is one option.

Here you can find many other options: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

0
source

I tried this and it worked for me: https://github.com/flowersinthesand/jquery-stringifyJSON

Previous solutions do not work for me, even this: https://github.com/douglascrockford/JSON-js

0
source

For those who cannot use third libraries, you can always use

 eval('var data = ' + request.responseText); 

to get the same functionality

0
source

All Articles