简体   繁体   中英

How to decode json file in php?

I want to get the data from json. My json file is like this

[[["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. 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 .

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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