用PHP解码json不起作用 [英] Decode json With PHP not working
本文介绍了用PHP解码json不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用PHP解码json,但不知道我在哪里错.这是我的代码
I am trying to decode json with PHP but dont know where am i wrong. Here is my code
$rr ='var modelsGlobal = [{"value":"FAFW3801LW","productdetailurl":"/Washers-Dryers/Washers/Front-Load/FAFW3801LW/"}{"value":"FAFW3801LW","productdetailurl":"/Washers-Dryers/Washers/Front-Load/FAFW3801LW/"}]';
$json = json_decode($rr, true);
foreach($json['modelsGlobal'] as $json){
$prod_id = $json["value"];
}
请帮助
推荐答案
您正尝试解码(破坏) JavaScript ,而不是JSON.
You are trying to decode (broken) JavaScript, not JSON.
JSON不会包含var modelsGlobal =
,并且数组成员之间需要一个,
.
JSON wouldn't include var modelsGlobal =
and array members need a ,
between them.
通过短毛绒来运行数据.
修复了阻止解析的错误之后,JSON并不是以带有modelsGlobal
的对象开头,因此直接在$json
中的数组上循环.
After you fix the errors which are preventing the parsing, the JSON doesn't start with an object with a modelsGlobal
, so loop over the array in $json
directly.
这篇关于用PHP解码json不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文