Parse JSON from server in javascript
Snippet
Instead of being asleep at 21:19 on 11 August 2009, kitt created this:
When a server response (say, from an ajax call) returns JSON formatted code, eval to bring the results into the script's space. Don't use with any returned JSON object that you don't really really really trust.
/* server returns {"a":1,"b":2,"c":3,"d":4,"e":5} */ // NEVER DO THIS var obj = eval('(' + jsontext + ')'); alert(obj.a); // will receive "1" in alert (no quotes) // DO THIS JSON.parse( json.data );
Add new comment