php - how to parse the json array elements using for loop to get the values one by one -
i have json array wherer pasre json till last element using loop number of array elements in json array ,i have more 3 objects in anarray ,so confused how parse json till last element, can idea
count($json); echo count; for(i=0;i<l=count($json);i++) { print value of each key }
i stuck ,because there no fixed lenght json getting server response may return 1 object 1 may twice or thrice or many ,so thought better loop ,as json contain more 1 json 3 keys ,such country can have more 1 state,and 1 state can have more 1 district ,plaese me,i stuck question last 2 days thank you
an idea :
function printjson($json) { foreach($json $index=>$value) { if(is_array($value)) { printjson($value); } else { echo 'value :'.$value.'<br />'; } } } $stringjson = "{'location':[{...}]}"; //for example printjson(json_decode($stringjson));
Comments
Post a Comment