I'm trying to decode a json file to a PHP variable, but the PHP variable is just null. This is my PHP:
$champions['names'] = json_decode(file_get_contents("file://D:/Xampp/htdocs/lol-champions.json"),true);
echo $champions['names']['champions'][1]['name'];
This is my json file:
"champions":[
{
"id" : 103,
"name" : "Ahri",
},
{
"id" : 84,
"name" : "Akali",
}]
答案 0 :(得分:2)
As @Paul Crovella stated, here is the correct version :
{
"champions": [{
"id": 103,
"name": "Ahri"
}, {
"id": 84,
"name": "Akali"
}]
}
Also if you want to call it;
echo $champions->champions[1]->name;