1. #1
    Ext User
    Join Date
    Apr 2010
    Posts
    5
    Vote Rating
    0
    olec is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    How you want to display the results in a grid , in "messageEntityList" there is multiple entry , if you specify

    Code:
    { name: 'body', mapping: 'messageEntityList[0].body '}
    you will get first one?

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Location
    Mexico City
    Posts
    9
    Vote Rating
    0
    lvyz is on a distinguished road

      0  

  4. #4
    Ext User
    Join Date
    Apr 2010
    Posts
    5
    Vote Rating
    0
    olec is on a distinguished road

      0  

    Default


    Quote Originally Posted by tomalex0 View Post
    How you want to display the results in a grid , in "messageEntityList" there is multiple entry , if you specify

    Code:
    { name: 'body', mapping: 'messageEntityList[0].body '}
    you will get first one?
    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

  5. #5
    Ext User
    Join Date
    Apr 2010
    Posts
    5
    Vote Rating
    0
    olec is on a distinguished road

      0  

    Default


    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.

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar