Làm cách nào để duyệt qua và hiển thị tên trong JSON sau bằng CodeIgniter?Làm cách nào để lặp qua đối tượng JSON
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Search extends CI_Controller {
public function index()
{
$json = '[{"name": "John Doe",
"address": "115 Dell Avenue, Somewhere",
"tel": "999-3000",
"occupation" : "Clerk"},
{"name": "Jane Doe",
"address": "19 Some Road, Somecity",
"tel": "332-3449",
"occupation": "Student"}]';
for (int $i = 0; $i < $json.length; $i++){
???
}
//$obj = json_decode($json);
//$this->load->view('search_page');
}
}
/* End of file search.php */
/* Location: ./application/controllers/search.php */
$ json không phải là một đối tượng json một chuỗi của nó. – Josh
+1 vì vậy tôi nên sử dụng json_decode ($ json) trước? – Anthony
Bỏ ghi chú dòng nói json_decode và chỉ lặp qua mảng mà nó trả về. (và điều này không liên quan gì đến CodeIgniter) –