To parse a JSON value, use
JSON.parse
. Then loop over all items to find the data you need:
var items = JSON.parse(yourJsonString).items;
var idToSearch = "1";
for (var i = 0; i < items.length; i++) {
if (items[i].id == idToSearch) {
var foundData = items[i].obj;
}
}
Also, your JSON string is invalid. There is a comma without data after it, and the outer object should be wrapped within
{}
braces. So, this data is valid:
{
"items": [
{
"id": "1",
"obj": {
"json": "1.json",
"js": "1.js",
"css": "1.css",
"text": "1.txt"
}
},
{
"id": "2",
"obj": {
"json": "2.json",
"js": "2.js",
"css": "2.css",
"text": "2.txt"
}
}
]
}