Ted Kendall
Posts: 0
Joined: Mon Aug 12, 2013 11:17 am

Serialize local variable data into array using JSON.stringify

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.

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Serialize local variable data into array using JSON.stringify

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

Ted Kendall
Posts: 0
Joined: Mon Aug 12, 2013 11:17 am

Serialize local variable data into array using JSON.stringify

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.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Serialize local variable data into array using JSON.stringify

Hello,

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

Return to “Issues”