Dave's Brain

Browse - Programming Tips - How can I parse JSON in any browser?

Date: 2009dec22
Language: javaScript
Warning: Now, I would recommend using jQuery to parse JSON

Q.  How can I parse JSON in any browser?

A.  Many browsers have a JSON.parse() function which is the best thing
to use.  But not all.  So use this function:

function parseJson(json) { var out; try { if (typeof JSON == 'object' && typeof JSON.parse == 'function') { out = JSON.parse(json); } else { out = eval('('+json+')'); } } catch(e) { // do nothing } return out; }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.