我想json在控制器中以格式显示响应,并且不希望在视图中移动.所以,请让我以任何方式让我能够表达json回应.
这是我想添加json标题的代码.
$result = $this->mod_doc->get_list();
echo json_encode($result);
Run Code Online (Sandbox Code Playgroud)
小智 26
试试这些.
public function signin() {
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
//add the header here
header('Content-Type: application/json');
echo json_encode( $arr );
}
Run Code Online (Sandbox Code Playgroud)
或尝试这种方式
return $this->output
->set_content_type('application/json')
->set_status_header(200) // Return status
->set_output(json_encode(array(your array)));
Run Code Online (Sandbox Code Playgroud)
小智 5
$result = $this->mod_doc->get_list();
$this->output
->set_content_type('application/json') //set Json header
->set_output(json_encode($result));// make output json encoded
Run Code Online (Sandbox Code Playgroud)
有关更多参考,请访问https://www.codeigniter.com/user_guide/libraries/output.html
| 归档时间: |
|
| 查看次数: |
16044 次 |
| 最近记录: |