{
"data": [
{
"business_type": "bar",
"business_name": "KKK",
"number": "1234567",
"business_id": "test1"
},
{
"business_type": "restauratns",
"business_name": "KKKK",
"number": "1234567",
"business_id": "test2"
}
]
}
PHP Code:-
1) Not Worked
foreach ($json_array->data as $obj) {
echo $obj->business_name;
echo $obj->business_type;
echo $obj->business_id;
}
2) Only get the output "data Array" but didn't get the object details
foreach ($json_array as $name=>$value) {
echo "$name: $value
";
foreach ($value as $entry) {
echo ' ' . $entry->business_type;
echo ' ' . $entry->business_name;
echo ' ' . $entry->business_id;
echo ' ' . $entry->number;
}
}
after this I also try to print details with print_r and var_dump.
Result of var_dump is :-
array(1) {
["data"]=>
array(2) {
[0]=>
array(4) {
["business_type"]=>
string(3) "bar"
["business_name"]=>
string(3) "KKK"
["number"]=>
string(7) "1234567"
["business_id"]=>
string(5) "test1"
}
[1]=>
array(4) {
["business_type"]=>
string(11) "restauratns"
["business_name"]=>
string(4) "KKKK"
["number"]=>
string(7) "1234567"
["business_id"]=>
string(5) "test2"
}
}
}
I am trying to find where I am making mistake but didn't get any idea. Please kindly guide me if anyone has any idea.