I have a JSON string like this
{"3560" : "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]
}
$.parseJSON() should be preferred.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.
obj.3560 should not work as a number is not a valid identifier.... does this really work for you?