API code from a template:
$country_array = array();
$country_array['data'] = array();
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
extract($row);
$country_item = array
(
'ID' => $ID,
'Name' => $Name,
'Population' => $Population,
'Area' => $Area,
);
// Push to "data"
array_push($country_array['data'], $country_item);
}
// Turn to JSON and output
echo json_encode($country_array);
JSON data:
{"data":
[{"ID":"1","Name":"Portugal","Population":"10286263","Area":"92212"},
{"ID":"2","Name":"United Kingdom","Population":"66836327","Area":"242495"}]}
I am not sure how to go about storing this data in PHP.
Here's what I have so far:
$response = file_get_contents('http://127.0.0.1/100520093/api/post/read.php');
$response = json_decode($response);
echo $response
The above results in an error message saying I cannot convert an object of Class stdClass to String.
Following the examples in W3Schools results in "data => Array".
Any help is appreciated, I'm still an amateur, so please go easy on me if this is an overly asked question, I could not find anything related to my particular case.