PDA

View Full Version : JSON DataModel Schema Question



griffiti93
20 Nov 2006, 4:35 PM
I am attempting to setup a JSON DataModel for use with a Grid. The server code is returning a collection of objects with plain vanilla JSON encoding, as such:



[{property: value, property: value},
{property: value, property: value},
{property: value, property: value}]


I don't really have a "root" as pointed out in the comments section of the JSONDataModel.js source file. I'm not sure if that's why I am not seeing anything or not. Is "root" required for the schema definition?

tryanDLS
20 Nov 2006, 4:57 PM
Yes - in the latest codebase it throws up an alert box error for this if you omit the 'root' tag from shema object. If you don't wrap your arry of items with a root property you get an empty grid div.

I don't think it's even valid JSON if you don't give the array a name

arnair
20 Nov 2006, 5:05 PM
Yeah, and I don't think JSON data should even start with an array (i.e. '[').

If you can change your server JSON output, this would be the ideal data format I think:


{ "rootobject": [
{ "property1":"value1-1", "property2":"value2-1" },
{ "property1":"value1-2", "property2":"value2-2" }
] }

Also see this thread for some related information:
http://www.yui-ext.com/forum/viewtopic.php?t=396

jack.slocum
21 Nov 2006, 3:31 AM
That's invalid json. There's a thread with a very simple workaround in the help forum.

griffiti93
23 Nov 2006, 6:48 AM
It works now! :D