0

I am trying to parse a json but i having problem to create model so how can i create effiecient model for json below so i can access def-id just by doing record.get('def_id'):

I am creating my model as:

Ext.define('MyApp.model.TodaysWord', {
extend: 'Ext.data.Model',

requires: ['MyApp.model.TodaysWordMenu'],

config: {
    fields: [
        {name: 'status', mapping: 'status'},
        {name: 'message', mapping: 'message'},
        {name:'data', mapping: 'data'},
        {name: 'definitions', mapping: 'definitions.defintion'},
        {name: 'ratings', mapping: 'definitions.rating'},
    ],
}
});

Ext.define('MyApp.model.TodaysWordMenu', {
extend: 'Ext.data.Model',
config: {
    fields: [
        'name',
        'author',
        'word_id',
        'category',
      'definitions',
      'rating',
      'def_id',
      'example',
      'author',
      'is_favourite'
    ],

    belongsTo: "MyApp.model.TodaysWord"
}
});

I am getting response my above model are incorrect and i am having hard time to solve it.

My json:

({
"accountInfo":{
    "expire_date":"2014-07-24 22:44:14",
    "subscribe_date":"2013-07-24 22:44:14",
    "time_remain":" 323 Days 22 Hours 2 Minutes",
    "status":"not expired"
},
"status":"TRUE",
"message":"Todays Word",
"data":[
    {
        "name":"paint",
        "author":"admin",
        "word_id":"1",
        "category":"Business",
        "definitions":[
            {
                "rating":"Green",
                "defintion":"to put color to in something",
                "def_id":"1",
                "example":null,
                "author":"admin",
                "is_favourite":"yesStar"
            },
            {
                "rating":"Red",
                "defintion":"this is a new definition of word paint.",
                "def_id":"42",
                "example":null,
                "author":"admin",
                "is_favourite":"noStar"
            }
        ]
    }
]
})

Any help would be appreciated.

Community
  • 1
  • 1
surhidamatya
  • 2,419
  • 32
  • 56

1 Answers1

0

You could use Ext.JSON.decode() and pass to it function your responseText. It would create you your needed object.

kuldarim
  • 1,096
  • 8
  • 21
  • 44