-
9 Apr 2010 2:54 AM #1
Cannot read nested arrays inside JSON
Cannot read nested arrays inside JSON
I have the following JSON-data:
{"list": [
{
"id": "330853",
"status": "1",
"categoryEntity": {
"id": "238",
"name": "The name",
"parentId": "111",
"isInternal": false
},
"messageEntityList": [
{
"id": "682485",
"body": "A message 1"
},
{
"id": "682486",
"body": "A message 2"
},
]
}
]
}
I'm having a problem to read/parse the "body"-item from the "messageEntityList"-item.
I was close to rewrite my code so it would produce a less "complicated" JSON, but
I soon saw I would run into a similar problem later on.
My field definitions are as follows:
{ name: 'id' },
{ name: 'title' },
{ name: 'name', mapping: 'categoryEntity.name'},
{ name: 'status' },
{ name: 'priority' },
{ name: 'body', mapping: 'messageEntityList.body '}
Additional source:
Initialized my store and reader like this:
var store = new Ext.data.Store({
url: ...
reader: new Ext.data.JsonReader({
root: 'list',
.
.
Any good advice?
Regards
Ole
-
9 Apr 2010 8:39 PM #2
How you want to display the results in a grid , in "messageEntityList" there is multiple entry , if you specify
you will get first one?Code:{ name: 'body', mapping: 'messageEntityList[0].body '}
-
9 Apr 2010 9:51 PM #3
-
11 Apr 2010 9:36 PM #4
Hi and thanks for take your time to reply.
I need to display all of the elements of messagEntityList, and the scalar of this list is not fixed.
So what I am looking for is a way to slurp a whole list.
My guess too would be that I would get the first element with that code example you added.
One solution for me would of course to join all the messageEntityList-elements before send JSON, so there will be only one object in the messageEntityList-field.
Regards
Olec
-
11 Apr 2010 9:44 PM #5
Well, if the nested element is a simple "hash"-structure, that would be the approach. But as I replied to tomalex0, I need to read a list of undefined size. So I have really two troubles. How to read the list and how to access each of the element of the list.


Reply With Quote