I need to store many values in single key of json. e.g.
{ "number" : "1","2","3", "alphabet" : "a", "b", "c" }
Something like this. Any pointers?
JSON array can store multiple values. It can store string, number, boolean or object in JSON array. In JSON array, values must be separated by comma.
There is no "error" if you use more than one key with the same name, but in JSON, the last key with the same name is the one that is going to be used. In your case, the key "name" would be better to contain an array as it's value, instead of having a number of keys "name".
Whitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON. It can also be minified with no affect to the data. Object literal names MUST be lowercase (ie – null, false, true etc).
Use arrays:
{ "number": ["1", "2", "3"], "alphabet": ["a", "b", "c"] }
You can the access the different values from their position in the array. Counting starts at left of array at 0. myJsonObject["number"][0] == 1
or myJsonObject["alphabet"][2] == 'c'
{ "number" : ["1","2","3"], "alphabet" : ["a", "b", "c"] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With