Reputation: 49
I can't loop data out from response array.
$.post(myurl , function(response){
for (var i = 0; i < response.result.length; i++) {
alert(response.result[i]);
}
},"json");
result of returned json array is :
{"result":["data one","data two","data three"]}
Upvotes: 0
Views: 283
Reputation: 3758
EDIT : In your head tag add json2.js. Go here and download it.
Then whenever u have a json string like the one in your question. Just use JSON.parse(somejsonstring);
var t = '{"result":["data one","data two","data three"]}' ; //Response Text
var p = JSON.parse(t); //p.result[0] will give u "data one"
Upvotes: 0
Reputation: 51
You can iterate over an object's properties with a for each loop:
for (var prop in response) {
alert(prop + ": " + response[prop]);
}
Upvotes: 1