Page 1 of 1

Serialize local variable data into array using JSON.stringify

Posted: Mon Aug 12, 2013 11:26 am
by Ted Kendall

Hi there, love building my app in Appery.io!

My question is today is regarding how to use JSON.stringify within the Appery.io panel.

Context:

I have several local storage variables: ContactName, ContactPhone, ContactEmail.

I would like to serialize these into an array and send the array as a request parameter to my backend service.

Questions:

  1. I understand I need to concatenate these variables and convert to a string (JSON.stringify), but I am not sure how to do this with local [dynamic] variables.

  2. Where can I implement this JS - within the Edit Mapping panel?

    Thank you so much for your time.


Serialize local variable data into array using JSON.stringify

Posted: Mon Aug 12, 2013 12:10 pm
by Oleg Danchenkov

Hi, Ted.
"Where can I implement this JS" - you can add JS to mapping. Try this
codevar arr = [], s;
arr.push(localStorage.getItem("ContactName"));
arr.push(localStorage.getItem("ContactPhone"));
arr.push(localStorage.getItem("ContactEmail"));
s = JSON.stringify(arr);
return s;/code


Serialize local variable data into array using JSON.stringify

Posted: Mon Aug 12, 2013 9:51 pm
by Ted Kendall

Hi Oleg, thank you so much.

As a quick follow up on this, on the response JSON object, I would need to reverse the above using JSON.parse() to convert the array back into multiple local storage variables. Would you be able to demonstrate how that might work or provide any pointers?

Thanks again.
Ted.


Serialize local variable data into array using JSON.stringify

Posted: Tue Aug 13, 2013 2:50 am
by Igor

Hello,

Please take a look at jquery docs: http://api.jquery.com/jQuery.parseJSON/