PDA

View Full Version : Issue with JSON Reader



xul8tr
19 Jul 2013, 8:51 AM
the following is not working for a WebService json result



reader: {
type: 'json',
totalProperty: 'totalProperty',
record: 'persons',
root: 'd'
}

Here is the data result:

{
"d":
[
{
"__type": "ExtJSGrid",
"totalProperty": 45,
"persons":
[
{
"__type": "RTWebGui.GridPerson",
"FirstName": "testFN",
"LastName": "testLN",
"MiddleName": "testMN",
"DisplayName": "testFN testMN testLN",
"Suffix": "",
"Rank": "1",
"Organization": "Company",
"Service": "A",
"IdNumber": "12345",
"Designation": "U",
"Affiliation": "A",
"Country": "US",
"Status": "W",
"Id": "12345",
"totalProperty": 45
}
]
}
]
}

mankz
20 Jul 2013, 3:41 PM
Your reader is misconfigured, your data exists at d.persons and this should be the root.


reader: {
type: 'json',
totalProperty: 'totalProperty',
root: 'd.persons'
}

jdflores
20 Jul 2013, 9:09 PM
I see the issue is with the interpretation of the 'record' config. This config is intended to specify a property inside the each one of the root's objects. This property will be considered by the store as the actual record's data, ignoring all the other properties.

In your data, that property 'persons' is an array and the store is expecting it to be an object.
If 'persons' is actually your record's array, remove square brackets on your root 'd' (now an array of one object) and just config the reader with root : 'd.persons'. If you choose to do this, you have to remove the 'record' property.

xul8tr
22 Jul 2013, 5:47 AM
I have tried using just 'd.persons' and it doesn't work. Before when i pushed a root object from the web service root: 'd' did work.

mankz
22 Jul 2013, 6:07 AM
Ok, will need to see a proper test case to help out further.

xul8tr
22 Jul 2013, 6:22 AM
I got it to work with

root: 'd[0].persons'

mankz
22 Jul 2013, 6:23 AM
Right, I missed that it was an array - good catch! :)