Walid Walid - 4 months ago 10
JSON Question

get JSON Parameters PHP

I am new to JSON and I am facing some difficulties , i am doing an

echo $response;
and i am getting:

{ "items": [ { "tableName": "CO.Affected_Country", "count": 1, "columnNames": [ "id" ], "rows": [ [ "12" ] ] } ], "links": [ { "rel": "self", "href": "https://ter.ge.com/services/rest/connect/v1.3/queryResults?query=x" }, { "rel": "canonical", "href": "x" }, { "rel": "describedby", "href": "x", "mediaType": "application/schema+json" } ] }


i am trying to get the 'row' value , so i am trying to use
$response->{"items"}->{"row"};
I know this syntax is wrong , but how can i do it?

Answer
$obj = json_decode($response);
$rows = $obj->items[0]->rows[0];

This is an array. To get the first value (12), you can then do:

echo $rows[0]

Live demo