I got the following JSON string in PHP:
{
"status":"200",
"message":"Saved picklist found",
"data":{
"_id":{
"$oid":"5aab871dbcdcab3ab0005cd3"
},
"username":"admin",
"list_count":"3",
"list":[
{
"id":"1",
"data":"AUTOGENERATED1",
"x":"33",
"y":"33"
},
{
"id":"2",
"data":"AUTOGENERATED2",
"x":"22",
"y":"22"
},
{
"id":"3",
"data":"AUTO",
"x":"33",
"y":"33"
}
]
}
}
that I decode to an array using the following:
json_decode($response, true);
I would like to loop through the array and extract for example username and list_count. I tried the following code for that:
foreach ($response['data'] as $resp) {
echo $resp['list_count'];
}
which does not work. Any suggestions on how to extract username and list_count?
I would also like to loop through the list
array and get the values for each object within that array, any suggestions on how that can be done?