开发者

How Can I Use This JSON data like array

I have json data like this:

{
  "Adobe Photoshop": "70",
  "Adobe Premier": "71",
  "Animasyon": "72",
  "AutoCAD": "73",
  "Bro\u01开发者_开发技巧5f\u00fcr & Bilet": "75",
  "CorelDraw": "76",
  "Flash": "77",
  "Grafik Tasar\u0131m": "68",
  "Karikat\u00fcr": "78",
  "Kartvizit Tasar\u0131m": "79",
  "Logo Tasar\u0131m": "80",
  "Poster": "81",
  "Reklam Tasar\u0131m": "74",
  "Ses D\u00fczenleme": "82",
  "Video D\u00fczenleme": "69",
  "Web Tasar\u0131m": "83"
}

First think(Adobe Photoshop) means tag name, second thing(70) means tag id. I want to use this information in jquery like array to build checkboxes for every tag. How can I done this ? Thanks


You're looking for a for in loop, like this:

for(var key in something) {
    if (!something.hasOwnProperty(key)) continue;    //Skip inherited members

    var value = something[key];
    //Do things...
}

Note that the iteration order is not defined.


Something like this?

http://jsfiddle.net/LKNKB/

var data = {"Adobe Photoshop":"70","Adobe Premier":"71","Animasyon":"72","AutoCAD":"73","Bro\u015f\u00fcr & Bilet":"75","CorelDraw":"76","Flash":"77","Grafik Tasar\u0131m":"68","Karikat\u00fcr":"78","Kartvizit Tasar\u0131m":"79","Logo Tasar\u0131m":"80","Poster":"81","Reklam Tasar\u0131m":"74","Ses D\u00fczenleme":"82","Video D\u00fczenleme":"69","Web Tasar\u0131m":"83"};

var $div = $('<div/>');

for(var name in data) {
    $('<input/>',{ type:"checkbox", value:data[name] }).appendTo($div);
    $('<label/>',{ text:name }).appendTo($div);
    $('<br/>').appendTo($div);
}

$div.appendTo('body');​


You want a for...in statement:

var i;
for (i in hash) {
    doSomething(i, hash[i]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜