read json array file with jquery

i saw that others had already posted a similar question but my json array is a bit different... perfectly valid (generated from json php function). What i what is return all the values form a particular key. Note that the key come from several links, i'm just parsing the ID. I didnt have any js code yet since anyway nothing works.

Per example, if i want to have the infos of id_10001. I must be able to retreive them. Note that i can't hardcode it since it's generated.

here's my json file :

{"id_10000":{
    "imgfilename":"asd1.jpg",
    "imgname":"image_name_test1",
    "imgdescription":"this is an example of a description"
    },
"id_10001":{
    "imgfilename":"asd2.jpg",
    "imgname":"image_name_test2",
    "imgdescription":"this is an example of a description"
    },
"id_10002":{
    "imgfilename":"asd3.jpg",
    "imgname":"image_name_test2",
    "imgdescription":"this is an example of a description"
    }}

Answers 1

  • Your JSON is an object, not an array. To access the infos of id_10001, use that as the property name.

    var id = 'id_10001';
    var data = json[id];
    var imgname = data.imgname;
    

Related Articles