How To Store Multiple Records In JSON
I wan't to know how store multiple entities in json file (Structure) I will want to find by id functions (JQuery/javascript) and easy sorting (0,1,2...200). Here my code: { 'i
Solution 1:
Btw, The answer by Lix below is best if you're looking to pull them out via their index number.
Wrap them in square brackets!
[{
"id" : 5,
"name" : "Jemmy overy",
"data" : {...},
"link" : "http:...",
},
{
"id" : 6,
"name" : "John Smith",
"data" : {...},
"link" : "http:...",
}]
Solution 2:
Well, the only way I can see to identify the JSON objects in that manner would be to use it's ID property as a key -
var a = {
'5':{
"id" : 5,
"name" : "AAA",
"data" : {...},
"link" : "http:..."
},'6':{
"id" : 6,
"name" : "BBB",
"data" : {...},
"link" : "http:..."
},
...
};
So you access them like an array -
a['5']
With regard to sorting, I don't think that there is any native way to sort JSON objects, but there are some other posts on the site that provide a helping hand - Sorting JSON by values
Post a Comment for "How To Store Multiple Records In JSON"