Steve
Steve

Reputation: 5952

Graceful Degradation with JSON.Parse

If a browser doesn't support JSON.parse, would it make sense to include json.js and call parseJSON in lieu?

So the code would looks something like:

var z;

if (JSON.parse)
    z = JSON.parse(yada);
else
    z = JSON.parseJSON(yada); 

Upvotes: 1

Views: 361

Answers (1)

Matti Virkkunen
Matti Virkkunen

Reputation: 65166

You could always use json2.js and keep using the standard JSON.parse/.stringify. json2.js adds those functions if the browser doesn't have them, with the same names so you can keep your calls simple.

Upvotes: 3

Related Questions