John Herdean
Posts: 0
Joined: Tue May 14, 2013 3:56 am

how to populate a listview from a json response?

yes i thought i invoked the service before like you said and didnt work. Well, i did exactly as you said and now it works. Thanks.

Brian6028327
Posts: 0
Joined: Tue Jul 09, 2013 1:21 pm

how to populate a listview from a json response?

I have the $ sign for the response array, but how do I reference it in JS?

Here's my mapping, and it works fine:
Image

Now, I'd like to use that in a piece of JS similar to this:
var response = JSON.stringify(data));
localStorage.setItem("json_response", response);

I'm guessing that "data" above should be "$" or something, but I haven't figured out how to make it work.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to populate a listview from a json response?

Hello! $ sign isn't connected with variables names in mapping. If you use your code on service success then variable where you retrieve entire responce is called "data". This code is correct:
codevar response = JSON.stringify(data));
localStorage.setItem("json_response", response); /code
If you want to add JS in mapping then value you map will be in "value" variable (no matter what field you map)

Brian6028327
Posts: 0
Joined: Tue Jul 09, 2013 1:21 pm

how to populate a listview from a json response?

I guess the part that is giving me trouble is that I am thinking all 4 fields under the $ sign could be saved as part of one arrayed variable.Would this be possible?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to populate a listview from a json response?

Hello! This is how it would be - will be saved an array containing 4 records.

Brian6028327
Posts: 0
Joined: Tue Jul 09, 2013 1:21 pm

how to populate a listview from a json response?

Hi,
I must be missing something dumb. Here's what I have, trying to use a local variable called 'testIt':

var response = JSON.stringify(data);
alert(response);
localStorage.setItem(testIt, response);
alert(testIt);

The first alert works with a nice string of all the data from the service, which is cool to see working, but the second alert does not return anything. Nothing happens, like it is not even there. I tried a few different combinations of quote marks and such, but with no luck.

BTW - Thanks for you help

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

how to populate a listview from a json response?

Hi,

Here is the code:
codevar response = JSON.stringify(data);
alert(response);
localStorage.setItem( "testIt", response ); //you don't have "testit" variable so place "testit" in quotes to declare this is a string
alert( localStorage.getItem( "testit" ) ); //read saved data here./code

Brian6028327
Posts: 0
Joined: Tue Jul 09, 2013 1:21 pm

how to populate a listview from a json response?

Thank you! Thank you! That is exactly what I was missing.

Kirit Vaghela
Posts: 0
Joined: Tue Aug 27, 2013 11:23 am

how to populate a listview from a json response?

How to load listview with stored response data?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to populate a listview from a json response?

Hello! Could you clarify your question?

Return to “Issues”