Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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,我无法从不同变量中的json获取数据 $outputData= json_encode($posts); //[{"post_content":"asdcsswad","post_title":"sanjog"}] $post_content=$outputData->post_content; $post_title=$outputData->post_title; 两个变量都为空使用json\u解码 $data = json_decode($outputData); $pos

我无法从不同变量中的json获取数据

$outputData= json_encode($posts); //[{"post_content":"asdcsswad","post_title":"sanjog"}]

$post_content=$outputData->post_content;
$post_title=$outputData->post_title;

两个变量都为空

使用
json\u解码

$data = json_decode($outputData);
$post_content = $data['post_content'];
$post_title = $data['post_title'];
json\u decode
返回数组,而不是对象

如果你想在PHP中使用它,为什么不直接使用
$posts

使用json_decode()。你有一个对象数组。它是
$outputData[0]->…
,或者您希望遍历所有数组项。警告:json\u decode()预期参数1为字符串,警告:json\u decode()预期参数1为字符串,