Page 1 of 2
REST-service: data-mapping - json array
Posted: Tue Jun 05, 2012 7:07 am
by HappyFive
I use a REST-service to read a JSON from an url.
The JSON contains a huge array containing 250 objects.
How can i get this whole array ?
In this data-mapping screen i can map the array to a local-storage variable or directy to a javascript.
The local-storage variable doesn ́t work because it can only store strings, is that correct ?
But when i map the array to a JavaScript my application crashes (the handy-screen turns black). Even if the javascript is doing nothing else than write the values to the console.
I realized that the javascript is called 250 times, one time for each element in the array, maybe there is a better way of reading this array ??
Thx a lot for help !
REST-service: data-mapping - json array
Posted: Tue Jun 05, 2012 4:02 pm
by maxkatz
You can use JSON.stringify() to convert JavaScript object to JSON string.
http://www.json.org/js.html
Instead of mapping, you can run JavaScript on service's success event, get the data and save it into local storage.
http://help.tiggzi.com/documentation/...
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 5:11 am
by Joseph Yeung
Hi, Max.
I was trying to do the JavaScript referred in the above, but the link doesn't seem to work anymore.
Could somebody point to the renewed documentation, please?
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 5:16 am
by maxkatz
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 8:16 am
by Joseph Yeung
Big thanks, Max.
My question is how can I (1) store the JSON file (returned by REST service) into the storage, and (2) show only the first JSON object (3) and wait until a 'next' button is pressed and then show the second JSON object.
Sorry for requiring such detailed instruction, but I've spent some time fumbling my way yet without results.
Thanks!
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 11:06 am
by Joseph Yeung
Sorry.
My bad. There was a typo in the documentation example and I just copied it!
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 11:58 am
by Joseph Yeung
Hi, Max.
Now that I have saved a copy of the JSON file (returned by the REST service of Tiggzi Database) in the local storage.
How could I show the objects (rows) one by one from the local storage?
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 2:29 pm
by Kateryna Grynko
Hello Joseph,
You save Rest Service data to localStorage variable. To use this data run following code:
codevar response = JSON.parse(localStorage.getItem("json_response"));/code
Array of rows will be saved in "response" variable. You'll be able to handle rows using JavaScript code.
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 2:44 pm
by Joseph Yeung
Hi! Katya.
Thanks for replying. Should I also do something like the following?
for (var i=0, l=localStorage.length; i<l; i++){
var key = localStorage.key(i);
var value = localStorage[key];
}
REST-service: data-mapping - json array
Posted: Tue Jan 08, 2013 3:23 pm
by Kateryna Grynko
codefor (var i=0, l=response.length; i<l; i++)
{
var row = response;
//Now row contains single object from database collection
alert(row.key1);
}/code
"key1" must be replaced with collection column name