user3681970 user3681970 - 6 months ago 17
JSON Question

parsing json with php curl

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'];

}

Answer

No need to use foreach use below code to get OrganizationName

 $response = json_decode($server_output, true);
 $response['data']['OrganizationName'];