试图将 json 文件解码为变量,但它只返回 null
trying to decode json file to variable but its only returning null
我正在尝试将 json 文件解码为 PHP 变量,但 PHP 变量仅为空。这是我的 PHP:
$champions['names'] = json_decode(file_get_contents("file://D:/Xampp/htdocs/lol-champions.json"),true);
echo $champions['names']['champions'][1]['name'];
这是我的 json 文件:
"champions":[
{
"id" : 103,
"name" : "Ahri",
},
{
"id" : 84,
"name" : "Akali",
}]
正如@Paul Crovella 所说,这是正确的版本:
{
"champions": [{
"id": 103,
"name": "Ahri"
}, {
"id": 84,
"name": "Akali"
}]
}
另外如果你想调用它;
echo $champions->champions[1]->name;
我正在尝试将 json 文件解码为 PHP 变量,但 PHP 变量仅为空。这是我的 PHP:
$champions['names'] = json_decode(file_get_contents("file://D:/Xampp/htdocs/lol-champions.json"),true);
echo $champions['names']['champions'][1]['name'];
这是我的 json 文件:
"champions":[
{
"id" : 103,
"name" : "Ahri",
},
{
"id" : 84,
"name" : "Akali",
}]
正如@Paul Crovella 所说,这是正确的版本:
{
"champions": [{
"id": 103,
"name": "Ahri"
}, {
"id": 84,
"name": "Akali"
}]
}
另外如果你想调用它;
echo $champions->champions[1]->name;