在不同的变量中获取php中的json数据
我无法从不同变量中的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
$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为字符串,