Home > DeveloperSection > Forums > How do query json for a value?
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    March-12-2013 3:41 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1315  View(s)
Rate this:

Hi!

How do I find out which "count"-id the loaded picture has?

The loaded picture is: "df5ddc27f7569f83e3867bec71a2cac0.jpg"
And my json are:

[
  {"count":1,"file":"8b6c5592f0378dc8c56e591a7b147826.jpg"},
  {"count":2,"file":"a44618c1afe93be486382ceb38536e02.jpg"},
  {"count":3,"file":"3c692942d69fba0d16971e0685f42757.jpg"},
  {"count":4,"file":"df5ddc27f7569f83e3867bec71a2cac0.jpg"}
]

Has anybody an idea for me?

Thanks in advance!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    March-12-2013 8:48 AM

Hi Mark!

I assume that you are trying to do this with JavaScript

var jsondata = [
  {"count":1,"file":"8b6c5592f0378dc8c56e591a7b147826.jpg"},
  {"count":2,"file":"a44618c1afe93be486382ceb38536e02.jpg"},
  {"count":3,"file":"3c692942d69fba0d16971e0685f42757.jpg"},
  {"count":4,"file":"df5ddc27f7569f83e3867bec71a2cac0.jpg"}
];

function getId(file) {
    for(var f in jsondata) {
       if(jsondata[f].file == file)
         return jsondata[f].count;
    }
}

var id = getId("df5ddc27f7569f83e3867bec71a2cac0.jpg"); //count-id


Don't want to miss updates? Please click the below button!

Follow MindStick