I have the following json :
{"returnCode":0,"returnMessage":"SUCCESS","data":{"OrganizationName":"ABC inc."}}
I wrote the following code to parse the organization name. But it is not working.
$response = json_decode($server_output, true);
foreach($response['data'] as $item)
{
echo $item['OrganizationName'];
}
No need to use foreach
use below code to get OrganizationName
$response = json_decode($server_output, true);
$response['data']['OrganizationName'];
i think json_decode() function work for you.
$array= curl_exec ($ch);
$server_output =json_decode($array);
$server_output->data->OrganizationName // output ABC inc.
If you want to access it as an array, typecast it.
$response = (array) json_decode($server_output);
There is no need to foreach you can directly access the Organization name.
Check below code
$server_output='{"returnCode":0,"returnMessage":"SUCCESS","data":{"OrganizationName":"ABC inc."}}';
$response = json_decode($server_output);
echo $response->data->OrganizationName; // ABC inc.