0

我正在尝试解析一个 json,但我在创建模型时遇到了问题,所以我怎样才能为下面的 json 创建有效的模型,这样我就可以通过执行 record.get('def_id')来访问def-id :

我正在创建我的模型:

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"
}
});

我收到回复,我的上述模型不正确,我很难解决它。

我的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"
            }
        ]
    }
]
})

任何帮助,将不胜感激。

4

1 回答 1

0

您可以使用Ext.JSON.decode()并将您的 responseText 函数传递给它。它会为您创建所需的对象。

于 2013-09-04T14:52:37.167 回答