... JSON Headache ...



• JSON Headache »»


Hey,

I'm having a problem with some JSON (specifically manipulating JSON retrieved the Google Gears httprequest function) - I'm retrieving JSON data which I've tried to parse using eval():
Code:
var response = request.responseText; // httprequest response
var jsRespObj = {};
jsRespObj = eval("(" + response + ")");
if(jsRespObj.results[0].error != null){
alert('Hi'); // never gets to this line
}
On the line jsRespObj.results[0].error I'm getting an error thrown: "jsRespObj.results is undefined".

It looks like the jsRespObj variable holds a String value, rather than a JSON object that can be manipulated...but I haven't any idea why.

The JSON data is valid, so printed after parse it looks like:
Code:
{"results":[{"cat_id":"1","cat_name":"A cat name","treat_group":[],"error":"Test"},{"cat_id":"2","cat_name":"Another Cat Name","treat_group":[],"error":"Test"}]}
Any suggestions on what the problem might be? I've been staring at it for a while and might be missing something obvious now!
 Bookmark with:            
Source: IrishWebMasterForums | pub: 17 Jul 2008 by: davkell | added: 17 Jul 2008 | cat: Coding Help | views: 13 time/s
Leave a Comment...
Name: *
Email: *
Comment: *
Security Code: security code
*
     Remember me:
Categories
Channels
Press Release