Thread: JSON Headache

View Single Post

  #1 (permalink)  
Old 17-07-2008, 04:50 PM
davkell davkell is offline
Coder
 
Join Date: Jul 2007
Location: Galway
Posts: 89
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Thanks: 0
Thanked 0 Times in 0 Posts
davkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud of
Default 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!
__________________
Not Work: My blog
Work: Website Design Galway
A little app: Twiteye.com (Application, software & service ideas from Twitter)
Reply With Quote