-
1 Apr 2012 8:54 PM #1
Answered: What reader will work with this Array / JSON data?
Answered: What reader will work with this Array / JSON data?
I'm calling a RESTful web service using the jsonp proxy for this URL:
http://fastmotorcycleservice.cloudap...svc/list/Bruno
The data that is returned is a sort-of mix between JSON and an array. Looks like so:
Code:["Test","Hello","Bananna","Apple"]
For the life of me, I cannot get a Reader to work with that data. I've tried using both Array and Json readers. Here's the code I'm using with an Ext.data.Store:
Any ideas what I can do to get that data format into my store? Thanks much.Code:Ext.define('SearchResult', { extend: 'Ext.data.Model', config: { fields: [ {name: 'name', type: 'string'} ] } }); var store = Ext.create('Ext.data.Store',{ model: 'SearchResult', autoLoad: true, proxy: { type: 'jsonp', url: 'http://fastmotorcycleservice.cloudapp.net/FastMotorCycleListService.svc/list/Bruno', // reader: { // type: 'json', // root:'' // } reader: { type: 'array', exception: function(rdr, resp, err, eOpt) { alert('error!'); } } } });
-
Best Answer Posted by mitchellsimoens
Just as an fyi for @"Larry Q", The array reader can read data like:
Code:[ ["field1", "field2"], ["foo", "bar"] ]
-
2 Apr 2012 4:38 AM #2
I am not sure if any of the predefined readers can interpret this data, so i think you're stuck writing your own.
The format should not be too hard to parse, though; i would suggest two alternatives:
1. extend from Json Reader, override the read method, modify the incoming string so it is valid json and let the json reader do the rest
2. extend from Reader and implement the full API yourself, parsing the string by hand using String.split('","') to extract your tokens
just a starting point, i am not really familiar with the reader API so maybe there probably are some more pitfalls to those alternatives..
-
2 Apr 2012 4:45 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 436
- Answers
- 3108
Just as an fyi for @"Larry Q", The array reader can read data like:
Code:[ ["field1", "field2"], ["foo", "bar"] ]Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Apr 2012 7:41 AM #4
Thanks for the replies. I'll try mucking around with the data string and get it into an acceptable format. Appreciate the help!


Reply With Quote