Storing arrays in localstorage

I'm building an app with It's basically a search app that returns results and then you can click into the results to see details.

Results are returned from a REST api in JSON format, and each results has a number of different items in it, including one that is a JSON array which contains multiple sets of three name/value pairs.

I need the array associated with each result to be available in the details page for that result. I don't want to simply run the search again in the details page, because it is a relatively lengthy process and would slow down the entire app.

I'm aware of using JSON.stringify() to make the array a string, and then storing each array in local storage. However, when I do that in, it seems that I either a) just save the first result of the array, or b) am doing it wrong.

Can any provide any insight into how I can go about doing this? Happy to provide code, clarify my question, etc.



If there's some problem using JSON.stringify() with, try the approach storing them as comma-separated string (unless you're having commas in values):

> ["foo", "bar"].join();
>> "foo,bar"

And them returning them:

> "foo,bar".split(",");
>> ["foo, "bar"]

Of course, if you're having commas in values, you can use explicitly specified separator for values, like:

> ["foo,bar", "foz,baz"].join("#");
>> "foo,bar#foz,baz"

Need Your Help

Error with prepareForSegue “”unexpectedly found nil while unwrapping an Optional value“”

ios swift

I'm trying to pass data from a one view controller to the next view controller with prepareForSegue function.

Added a field to a table in the database - how to make Entity edmx respond?

sql-server entity-framework .net-4.0 edmx

I tried rebuilding but it seems that the edmx file doesn't update itself with the changes I made. Any suggestions besides removing the edmx and remaking it?