views:

59

answers:

3

hi, I have json data like this:

{"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"}

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

+3  A: 

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.

SLaks
+1  A: 

You want a for...in statement:

var i;
for (i in hash) {
    doSomething(i, hash[i]);
}
Tobias Cohen
+1  A: 

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');​
patrick dw