PDA

View Full Version : Traverse JSON Data



sridhar.boganathan
2 Apr 2012, 4:39 AM
Hi All,

I have JSON data as a string object. I need to convert the JSON string into JSON object. And also, I should be able to parse the JSON Objects. I was trying to use DomQuery.select for parsing. I could not parse and I could not trace the JSON Object.

{
"data": {
"id": "root",
record: [
{
"id": "1",
"name": "xxx"
},
{
"id": "2",
"name":"yyy"
},
{
"id":"3",
"name":"zzz"
},
{
"id":"4",
"name":"aaa"
}
]
}
}



Here, I need to trace 'record' in a for loop.

Please share.
-Sridhar

skirtle
2 Apr 2012, 6:16 AM
There isn't a JSON object as such, you'd just use a JavaScript object. To parse a JSON string to a JavaScript object use Ext.decode.

JSON of the kind you posted is usually read into a store. For that you wouldn't need to parse it yourself, you'd just need to configure a suitable reader.

sridhar.boganathan
3 Apr 2012, 12:30 AM
There isn't a JSON object as such, you'd just use a JavaScript object. To parse a JSON string to a JavaScript object use Ext.decode.

JSON of the kind you posted is usually read into a store. For that you wouldn't need to parse it yourself, you'd just need to configure a suitable reader.

Thanks, As you said. I have created Reader for JSON Object. It is working now.

-Sridhar