Php Json how to get property?

I have a json file. I would like to get "Zangya" (which is in "animeName")
$datas = file_get_contents('getCharacters.json');
$datas = json_decode($datas);
var_dump($datas[0]);
$datas = file_get_contents('getCharacters.json');
$datas = json_decode($datas);
var_dump($datas[0]);
This gives me: object(stdClass)#1 (26) { ["animeName"]=> array(1) { [0]=> string(6) "Zangya" } ["address"]=> NULL ["aliasName"]=> array(3) { [0]=> string(3) "Aki" [1]=> string(8) "Zangyaku" .......
2 Replies
lanszelot
lanszelotOP6mo ago
I tried this:
$datas = file_get_contents('getCharacters.json');
$datas = json_decode($datas);
$array = json_decode(json_encode($datas[0]), true);
echo ($array["animeName"][0]);
$datas = file_get_contents('getCharacters.json');
$datas = json_decode($datas);
$array = json_decode(json_encode($datas[0]), true);
echo ($array["animeName"][0]);
I got it, thank you
ἔρως
ἔρως6mo ago
be careful when using that parameter, as large arrays can use a whole lot more memory than an object, for some bizarre reason php got a lot better on this aspect, but still, keep an eye out for it so, instead of doing$array['animeName'][0] you can do $array->animeName[0], id you dont set it to decode to an array
Want results from more Discord servers?
Add your server