php - Processing json where the number of json array is dynamic -


i have json response php ajax. thing depending on value entered in text box number of json arrays vary. example: may return {"count1":10, "ccc1":30} , {"count1":10, "ccc1":32, "count2":40, "ccc2":123,"count3":32,"ccc3":21}. extract value in jquery way:

success: function(response){     var count = response.count1;     //do } 

but since number of counts different used loop. question can figure out how many of them receiving how can process them? var count = response.count needs specific right? cannot concate strings this:

var count = 0;     while(something){     count = count + 1;     var str = "count"+count;     var whatever = response.str; } 

so, can please me suitable solution in case?

you on right track there. should work you.

var = 1; while(response['count' + i]) {     var count = response['count' + i++]; } 

you can access properties if array indices. response['count'+i] works.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -