Codeigniter的RESTful API的JSON响应是在JSON前面插入HTML,导致JSON响应在我真正进入JSON之前死掉。我使用POSTMAN进行测试,并且它给了我
SyntaxError: Unexpected token < in JSON
这是原始回复:
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
{"status":"success","message":[{"listitem_title":"Religion, Secularism, and Constitutional Democracy (Religion, Culture, and Public Life)","listitem_author":"","listitem_url":"https:\/\/stpsu.on.worldcat.org\/search?queryString=bn:9780231168717","listitem_img":"http:\/\/ecx.images-amazon.com\/images\/I\/41ed54Udo6L.jpg","listitem_id":"328","list_name":"New bookss Aug 29","page_list_id":"50","list_description":"New books for August 29","inst_id":"1"}..........
所以它正在回归一些东西。但它之前插入HTML ......太令人沮丧......
这是我的控制器:
function featuredslideshow_get(){
//calls the featured slideshow data in JSON format
$inst_id = $this->uri->segment(3);
//locate featured pagelist ID
$inst_data = $this->user_model->get_config($inst_id);
//set pagelist ID
$featured_id = $inst_data->featured_pagelist;
//Find and search for featured items by pagelist ID
$titles = $this->pagelist_model->pagelist_with_items($featured_id);
if(isset($titles)){
$this->response(array('status' => 'success', 'message'=> $titles));
}else{
$this->response(array('status' => 'failure', 'message' => 'The specified institution could not be found' ), REST_Controller::HTTP_NOT_FOUND);
}
}//end of featured slideshow
有没有人对如何摆脱这个HTML有任何想法,只是使用这个PHP库有RAW JSON?非常感谢