HOW DO QUERY JSON FOR A VALUE?

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
 1665  View(s)
Ratings:
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!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How do query json for a value?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!