Iterate JSON string
I have a JSON string like this
{"3开发者_如何学JAVA560" : "something", "3980" : "something", "4580" : "1456"}
How to get data above as "key -> value" in javascript(jquery) ?
var obj = JSON.parse(jsonString);
Now you can access obj["3560"]
, etc.
Or iterating:
for(var key in obj) {
// do something with obj[key]
}
var obj = jQuery.parseJSON(jsonObj);
Then you could access the data like obj.3560
or obj.3980
or iterate over them using a for-in loop like in Felix Kling's answer.
This requires jquery 1.4.1 or later to work.
精彩评论