Answer the question
In order to leave comments, you need to log in
How to correctly access JSON in PHP?
The following response comes from the API:
{
"status": "ok",
"meta": {
"count": 1
},
"data": {
"37677272": [
{
"all": {
"spotted": 75,
"avg_damage_blocked": 65.24,
"capture_points": 100,
"explosion_hits": 0,
"piercings": 299,
"xp": 32706,
"survived_battles": 11,
"dropped_capture_points": 50,
"damage_dealt": 37598,
"hits_percents": 63,
"draws": 0,
"battles": 41,
"damage_received": 27929,
"frags": 56,
"direct_hits_received": 189,
"hits": 404,
"battle_avg_xp": 798,
"wins": 20,
"losses": 21,
"piercings_received": 157,
"no_damage_direct_hits_received": 32,
"shots": 641,
"explosion_hits_received": 4,
"tanking_factor": 0.12
}
}
]
}
}
...
$acid = (string)$a_ui;
$obj1->data->$acid[0]->all->spotted;
Answer the question
In order to leave comments, you need to log in
if you need to address the object, then you can write
it like this: $obj1->data->{'37677272'}->all->spotted;
- the last option is also working
And this one too:
$s = $obj1->{'data'}->{'37677272'}->{'all'}->{'spotted'};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question