For some reason I am not getting the expected output from json_decode. The JSON string comes back from an API call and the first part of the string looks as follows:
{"droplets":[{"id":67892618,"name":"NEW-TEK","memory":8192,"vcpus":4,"disk":20,blah blah blah
Here is the relevant portion of the code I am using:
function Test() {
$ch = curl_init('https://api.digitalocean.com/v2/droplets?tag_name=MYTAG');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer MYTOKEN','Content-Type: application/json'));
$json = curl_exec($ch);
$obj = json_decode($json,true);
echo 'Just making sure everything is working up till here!';
echo "\n\n";
$id = $obj->{'id'};
echo 'Droplet ID: ';
echo $id;
exit;
}
Ignore all the random echo lines and new line stuff. Just making the example easy to read. As you can see, nothing is getting pulled out of the array and echoed.