HappyFive
Posts: 0
Joined: Wed May 23, 2012 8:01 am

REST-service: data-mapping - json array

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 !

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

REST-service: data-mapping - json array

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/...

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

REST-service: data-mapping - json array

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?

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

REST-service: data-mapping - json array

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!

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

REST-service: data-mapping - json array

Sorry.

My bad. There was a typo in the documentation example and I just copied it!

Image

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

REST-service: data-mapping - json array

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

REST-service: data-mapping - json array

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.

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

REST-service: data-mapping - json array

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];
}

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

REST-service: data-mapping - json array

codefor (var i=0, l=response&#46;length; i<l; i++)
{
var row = response;
&#47;&#47;Now row contains single object from database collection
alert(row&#46;key1);
}/code
"key1" must be replaced with collection column name

Return to “Issues”