简体   繁体   English

如何在php中解码json文件?

[英]How to decode json file in php?

I want to get the data from json. 我想从json获取数据。 My json file is like this 我的json文件是这样的

[[["test demo","",,,0]],,"vi",,,,0.58984375,,[["vi"],,[0.58984375]]]

I want to get the data "test demo" so i create code like this 我想获取数据“测试演示”,所以我创建了这样的代码

$html = file_get_contents("jasonfile");
$obj1 = json_decode($html, true);

echo $obj1[][][];

but it does not working. 但它不起作用。 what i am doing wrong please help me on this.. 我做错了,请对此提供帮助。

JSON is not valid, it doesn't allow several commas in row. JSON无效,它不允许连续输入多个逗号。 Changing it to: 更改为:

[[["test demo","",0]],"vi",0.58984375,[["vi"],[0.58984375]]]

And running: 并运行:

$obj1 = json_decode(...yourinput...); echo $obj1[0][0][0];

correctly outputs test demo . 正确输出test demo

Try this: 尝试这个:

[[["test demo","","","",0]],"","vi","","","",0.58984375,"",[["vi"],"",[0.58984375]]]


$html = file_get_contents("jasonfile");
$obj1 = json_decode($html, true);

echo $obj1[0][0][0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM