Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php json_解码不工作,json_last_error()thows 4_Php_Json - Fatal编程技术网

php json_解码不工作,json_last_error()thows 4

php json_解码不工作,json_last_error()thows 4,php,json,Php,Json,我的英语很差。如果有什么不礼貌的话,我很抱歉。 感谢您抽出时间阅读我的问题 当我使用PHP函数json_decode()时,我得到null,json_last_error()抛出4。 谢谢你的帮助 我的PHP代码是 $str = file_get_contents("cache.txt"); $str = htmlspecialchars_decode($str); $arr = json_decode($str, true); print_r($arr); echo $errorinfo =

我的英语很差。如果有什么不礼貌的话,我很抱歉。 感谢您抽出时间阅读我的问题

当我使用PHP函数json_decode()时,我得到null,json_last_error()抛出4。 谢谢你的帮助

我的PHP代码是

$str = file_get_contents("cache.txt");
$str = htmlspecialchars_decode($str);
$arr = json_decode($str, true);
print_r($arr);
echo $errorinfo = json_last_error();
名为cache.txt的文件的内容为:

[[1,[0,"wWfxgeyEgrRf1M",["https://encrypted-tbn0.gstatic.com/images?q\u003dtbn%3AANd9GcTFekou1VcAkVW23s69_Q53CsUJD0syjACwY0jHbRYcRIcr5cyp",225,225],["https://www.hijordan.com/image/cache/catalog/Jordan-Retro-1/Jordan-Retro-1-16-1080x1080.jpg",1080,1080],null,2,"rgb(160,42,51)",null,false,{"2001":[null,null,null,21,18,3,3,null,null,null,[]],"2003":[null,"M3A7LEiRdcA0DM","https://www.aljadid.com/efabshop/air-jordan-retro-1-red-black-white-p-16.html","Nike Air Jordan Retro 1 Red Black White - Buy Air Jordan 1 Retro ...",null,false,null,null,null,false,null,null,"Al Jadid",null,null,null,null,null,null,null,null,null,false,false,false,{"26":[null,2]}],"2006":[null,[4.0,null,"Air Jordan Retro 1 red black white",null,"A stepping stone to the world of Air Jordan is the Original air jordan 1  (I) White Black Red, which was worn by Michael Jordan the majority of the  ...",null,true,5,60.85,"USD"]],"2008":[null,"Nike Air Jordan Retro 1 Red Black White ..."],"183836587":["aljadid.com"]}],null,[177,158,null,null,null,177,177,null,null,-10,null,null,false,true,null,null,[]],0,null,null,"wWfxgeyEgrRf1M",1,null,null,null,null,[[1580879352798185,178652430,3708684377],null,2]],[1,[0,"sFUMQKdZQFRaGM",["https://encrypted-tbn0.gstatic.com/images?q\u003dtbn%3AANd9GcSV5L3VvYWthX-IG9QO5QfLN_6eLvA687_og435LmF6_5NmGSI4",225,225],["https://www.hijordan.com/image/cache/catalog/air-jordan-12/air-jordan-12-49-1080x1080.jpg",1080,1080],null,2,"rgb(160,58,51)",null,false,{"2001":[null,null,null,21,18,3,6,null,null,null,[]],"2003":[null,"pTPqQEjGfZF7JM","https://togaf9-cert.opengroup.org/bcabshop/air-jordan-12-retro-black-varsity-red-p-1138.html","Air Jordan 12 Retro Black Varsity Red , Price: $89.90 - Air Jordan ...",null,false,null,null,null,false,null,null,"TOGAF? 9 Certification",null,null,null,null,null,null,null,null,null,false,false,false,{"26":[null,2]}],"2006":[null,[4.0,null,"Air Jordan 12 Retro Black Varsity Red","Nike","You should not miss the chance if you have not got one like the Air Jordan  12 Retro Black Varsity Red. Fine craftsmanship with premium materials like  ...",null,true,5,89.9,"USD"]],"2008":[null,"Air Jordan 12 Retro Black Varsity Red ..."],"183836587":["togaf9-cert.opengroup.org"]}],],]

这意味着您的JSON有语法错误,请通过验证程序运行JSON,您将看到它失败的地方。实际上,看起来必须删除结尾处的尾随逗号,然后它才能工作。最后,将
]}]、]、]
替换为
]}]]
尾部逗号创建问题。移除它们,它就会工作。@Qirel的建议。