PHP在JSON中查找值
我不知道这为什么不起作用。计数返回的数组大小正确 以下是mWeb.json文件:PHP在JSON中查找值,php,json,Php,Json,我不知道这为什么不起作用。计数返回的数组大小正确 以下是mWeb.json文件: [{"Title": "Some-Name","h1": "Some-h1-words", "Comments": "Some Comment", "Comments2": "Some Comment2"}, {"Title": "Some-Name b","h1": "Some-h1-words b", "Comments": "Some Comment b", "Comments2": "Some Co
[{"Title": "Some-Name","h1": "Some-h1-words", "Comments": "Some Comment", "Comments2": "Some Comment2"},
{"Title": "Some-Name b","h1": "Some-h1-words b", "Comments": "Some Comment b", "Comments2": "Some Comment2 b"},
{"Title": "Some-Name c","h1": "Some-h1-words c", "Comments": "Some Comment c", "Comments2": "Some Comment2 c"}]
代码如下:
<?
$url = 'mWeb.json';
$JSON = file_get_contents($url);
$someName = "Some-Name";
$data = json_decode($JSON);
echo count($data);
for($x=0; $x<count($data); $x++){
if($data[$x]['Title']==$someName){
echo '[{"Title":"'.$data[$x]["Title"].'","h1":"'.$data[$x]["h1"].'","Comments":"'.$data[$x]["Comments"].'","Comments2":"'.$data[$x]['Comments2'].'"}]';
}
}
?>
所有回波都是阵列的长度-回波计数($data) 如果您var\u dump($data)
您将看到您的对象是。。。物体
要获取关联数组,请执行以下操作:
$data = json_decode($JSON,true);
如果你var\u dump($data)
你会看到你的对象是。。。物体
要获取关联数组,请执行以下操作:
$data = json_decode($JSON,true);
哇,就因为我删掉了“真的”-谢谢哇,就因为我删掉了“真的”-谢谢