Hello All,
I have a JSON string that is formated as such:
{'total':999,'rows':[{'1','Bob','Gardener"},{'2','Bill','Accountant'}]}
I havn't been able to figure out how to use this in a JsonReader or JsonStore because the values have no names attached to them and I havn't figured out how to map names to them. So if I try to do:
var store = new Ext.data.JsonStore({
root: 'rows',
data: data,
fields: ['id','name','occupation']
});
The store has no idea what I am trying to get. Is there a way to use an ArrayReader inside of a JsonReader so I can get down to the root of rows and then use an ArrayReader to get the arrays out of there?
I'm sure this is a simple problem but I just can't seem to find the answer. Any help will be greatly appreciated.
Thank you for your time.
The json you return has to be formatted correctly to map to the store. Cutter's Crossing: ColdFusion 8 Json Return Format and ExtJS:: May 5, 2008 ColdFusion Development, Life, and Other Stuff: ColdFusion 8 Json Return Ext provides a number of 'Store' types, and 'reader's for parsing through them. with this issue, and parked a solution right on the Ext Forums. It's in the way that Ext's JsonReader expects the data to be formatted. http://blog.cutterscrossing.com/index.cfm/2008/5/5/ColdFusion-8-Json-Return-Format-and-ExtJSHOME |
{'total':999,'rows':[{id:'1',name:'Bob',occupation:'Gardener"},{id:'2',name:'Bill',occupation:'Accountant'}]}
That's what I was afraid of. It looks like we are going to have to redo our JSONHelper class to format the JSON correctly.
Thank you for your reply.
If you are creating JSON strings using your own classes, I suggest you look at the code at http://json.org/ It's excellent. We use the Java version to create all our configs that are set up by server-side analogs of UI controls.
We are using the java versions of the JSON helpers but we downloaded them a long time ago (before I got to this job) and I believe they made their own JSONHelper method to create a JSON Array vice a JSON Object due to the requirements of some graphing software they were using.
I might have to look into the code a little more and find/write a better method to use than the one we are currently using.
This is an uphill battle right now because the developers I work with have built similar things to those that are in Ext (i.e. event manager, combo boxes, generic table builder), but none of those things talk to each other properly and in some instances Ext does them better, but because we already have all this functionality and we have to meet our deadlines, it is difficult for them to look into Ext as an alternative.
Ext is faster, more optimized, and better suited for our tasks, but getting developers, that are both stuck in their ways and in a time crunch, to look at Ext is going to be interesting.
Thanks for your help, it is greatly appreciated.
BTW, Animal, I especially appreciate the Java code that you place on the forums. I'm very new to Java (and Struts and MVC), so seeing your examples has helped me understand a few things. I know these forums are really for Ext and client side implementation, but it seems like it would be a great idea to have a server side implementation section where people who are new to Java (php, asp, coldfusion) could go an find advice on how to properly build the server side code so that it is easier to implement with Ext. Just a thought, and thank you again for your great help.
Yes, you are. That "JSON" was not a valid Javascript object literal.
Just try using the statement
var x = {'1','Bob','Gardener"};
You could use an ArrayReader, and use
['1','Bob','Gardener"]
The json you return has to be formatted correctly to map to the store.
{'total':999,'rows':[{id:'1',name:'Bob',occupation:'Gardener"},{id:'2',name:'Bill',occupation:'Accountant'}]}
If you are creating JSON strings using your own classes, I suggest you look at the code at http://json.org/ It's excellent. We use the Java version to create all our configs that are set up by server-side analogs of UI controls.
Get Smart About Monitoring Virtual Machines
Microsoft Gets Ex-Streamly Cozy with U.K.'s MediaWave
|