Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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中查找值_Php_Json - Fatal编程技术网

PHP在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

我不知道这为什么不起作用。计数返回的数组大小正确

以下是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 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);

哇,就因为我删掉了“真的”-谢谢哇,就因为我删掉了“真的”-谢谢