echo $someJSON=json_encode($resultData);
输出为{"status":true,"postData":[{"post_id":"3","post_title":"JAVA","post_desc":"JAVA DESCRIPTION","status":"1"},{"post_id":"1","post_title":"PHP API","post_desc":"MAKING PHP API","status":"1"}]}
从输出中,如何使用PHP获取'post_title'的值?
答案 0 :(得分:0)
$arr = json_decode('{"status":true,"postData":[{"post_id":"3","post_title":"JAVA","post_desc":"JAVA DESCRIPTION","status":"1"},{"post_id":"1","post_title":"PHP API","post_desc":"MAKING PHP API","status":"1"}]}');
foreach($arr->postData as $post) {
$title = $post->post_title;
}
答案 1 :(得分:0)
$resultData
已经是一个对象,因此您无需转换它。
只需像任何其他对象一样访问其属性。
例如:
foreach($resultData->postData as $data) {
echo $data->post_title, ', ';
}
答案 2 :(得分:0)
您必须先使用json_decode
$someJson = json_decode('{"status":true,"postData":[{"post_id":"3","post_title":"JAVA","post_desc":"JAVA DESCRIPTION","status":"1"},{"post_id":"1","post_title":"PHP API","post_desc":"MAKING PHP API","status":"1"}]}');
foreach ($someJson->postData as $data){
echo $data->post_title;
}