我想呼應了JSON陣列像這樣的對象的每一個元素:如何去通過JSON陣列的每個元素在PHP
{"request_list":[{"id":"1","name":"yunus","surname":"smsk","phone_number":"05350601922","blood_type":"0","unit_of_blood":"0","date":null},{"id":"3","name":"yunus","surname":"smsk","phone_number":"05350601922","blood_type":"0","unit_of_blood":"0","date":null}]}
但我不能做它。我試過somethinglikethis:
$object = json_decode($json, true);
$request_list = $object->request_list;
foreach($request_list as $r){
echo $r->name;
echo $r->blood_type;
echo $r->phone_number;
}
但我得到了如下錯誤:
的foreach爲無效的論點提供()
擺脫真正的作爲json_deocde第二個參數,通過設置真正的你轉換對象數組。 – Styphon
如果第二個參數爲true,則Json將被轉換爲php數組。刪除json_decode中的第二個參數。 –