Able Alias Able Alias - 5 months ago 10x
PHP Question

php response body as object array, how to parse the content

one of the API return response as object array, I json encode the object array as below

{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"MISSING_REQUIRED_PARAMETER","detail":"Missing required parameter.","field":"amount_money.amount"}]}

I want to get the detail field value, how to get it.


You can read detail field right away from response array.

$json = '{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"MISSING_REQUIRED_PARAMETER","detail":"Missing required parameter.","field":"amount_money.amount"}]}';

I'm converting your JSON to Array just for example.

//Actual Array Response
$a = json_decode($json, true);

echo "<pre>";
echo "</pre>";

//Save detail to Variable
$detail = $a['errors'][0]['detail'];
echo $detail;