Today I have a Ajax solution where the server keeps track of selections are doing and updates the page. I’m redoing this so it will be all done with javascript on the client until the user actually submit the data, performance where quite bad under load with the old solution. (C#, ASP.NET 4.0)
Found a nice way of storing an Array by first serialize it with json link text
Say I have an array like this: {Id, Value}
Any advise how I can store several of the arrays above to a cookie?
That’s not an array. That’s an object. You can multiple copies of those in an array:
That’s a valid JSON string for an array containing objects —in this case, objects with a single property,
foo, each of which has its own value, but the objects don’t have to have the same properties, and they can have multiple properties. For instance:That’s a valid JSON string for an array with five entries:
f0,f1,f2, andall.f0,f1, andf2all have string values;allhas an array of strings as a value.You can turn an object or array into a valid JSON string (stringify), and reverse the process (parse) client-side using any of several libraries. Crockford (the inventer of JSON) has several on his github page, most notably json2.js although json2.js relies on
evalfor parsing; since that’s not really ideal you can usejson_parse.js(a recursive descent parser that doesn’t useeval) orjson_parse_state.js(a state machine that doesn’t useeval) instead.