PDA

View Full Version : Problem loading nested JSON



jamesmacfie
27 Jul 2011, 2:58 PM
Hey everyone,

I've been at this for a while now and I'm hoping my issue is simple. I'm having a problem loading some nested JSON. I've seen a few examples around where the common solution is to specify the root of the JSON and then to specify the record you want under that (or at least that's how I understand it).

I've tried testing my JSON after removing the first level of the info and changing the root and removing the record specifications and that works fine. It's just when I try to load the second level that nothing works.

My JSON:

{
"ArrayOfWorkspace": {
"Workspace": [
{
"Id": "1",
"Title": "Large Education Project",
"Status": "OnTrack",
"StartDate": "2011-07-01T14:00:00",
"EndDate": "2011-07-23T14:00:00"
},
{
"Id": "2",
"Title": "Financial System Upgrade",
"Status": "AttentionNeeded",
"StartDate": "2011-07-14T00:00:00",
"EndDate": "2011-08-04T00:00:00"
},
{
"Id": "3",
"Title": "Large Government Project",
"Status": "OnTrack",
"StartDate": "2011-07-14T14:00:00",
"EndDate": "2011-07-21T14:00:00"
}
]
}
}

And the my code to deal with this info:

App.stores.workspaceStore = new Ext.data.JsonStore({
model: 'Workspace',
sorters: [{
property: 'Title',
direction: 'DESC'
}],
proxy: {
type: 'ajax',
url: 'Data/workspaces.json',
reader: {
type: 'json',
root: 'ArrayOfWorkspace',
record: 'Workspace'
}
}
});

Is there something I'm missing? At the moment I can't modify the JSON I'm getting back.

Thanks,

James

jamesmacfie
27 Jul 2011, 3:11 PM
Right on, I got it all sorted now.

To go down a level in my case I can specify the root as

root: 'ArrayOfWorkspace.Workspace'