Im not sure how to exactly get values (access objects and show them on page, or store as variables, etc. just I want to get those IDs (9473, 5649, 7953 .......) from JSON output.
Adding the URL which I am decoding, so you can take a look at it, cos Im really confused. Either I got undefined strClass or non-object error :/
The source API URL is:
api.worldoftanks.eu/wot/account/tanks/?application_id=demo&fields=tank_id&account_id=503066565
Function to get content from URL:
function get_url_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
This is print of JSON return I get (1, 2 ......... 89):
stdClass Object
(
[status] => ok
[count] => 1
[data] => stdClass Object
(
[503066565] => Array
(
[0] => stdClass Object
(
[tank_id] => 9473
)
[1] => stdClass Object
(
[tank_id] => 5649
)
[2] => stdClass Object
(
[tank_id] => 7953
)
[89] => stdClass Object
(
[tank_id] => 64817
)
)
)
)
This is raw JSON output (its much longer, but its mainly same, just more tank_ids there):
{"status":"ok","count":1,"data":{"503066565":[{"tank_id":9473},{"tank_id":5649},{"tank_id":7953},{"tank_id":64817}]}}
I tried to get data from it in couple of ways, but problem is, that ID (503066565) is Array and every time I get error about non-object data or Undefined property: stdClass:
Im used to get data from JSON when there is no array, so Im little bit confused now.
Also I use PHP.
Commented code is sample of things I tried (and I tried like 20 possible options that came to my mind), but I dont work with JSON output often, so I need your help.
$wg_id = "503066565";
$wot = json_decode(get_url_contents("URL"));
//$tank_id = $wot->data->$wg_id->in_garage;
/*
$tank_id = $wot->data->$wg_id['in_garage'];
foreach ($wot as $i){
echo $i['tank_id'];
}
*/
echo $tank_id;
How can I get all those data out (maybe to array)? I need them to compare those IDs when selecting stuff from DB. Also there might be another value in_garage, is there option to add it to array and know which values are together (you know, each in_garage is for specific tank_id).