SyntaxError:JSON位置0处出现意外的令牌C-Ionic 2 Http GET请求 [英] SyntaxError: Unexpected token C in JSON at position 0 - Ionic 2 Http GET request
本文介绍了SyntaxError:JSON位置0处出现意外的令牌C-Ionic 2 Http GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行GET
请求并从响应中检索数据.
this.http.get('http://localhost:8888/maneappback/more-items.php').subscribe(res => {
console.log(res.json());
}, (err) => {
console.log(err);
});
我收到错误SyntaxError: Unexpected token C in JSON at position 0
.我还假设该错误与请求有关.
在服务器端,我像这样(PHP)发送数据:
echo json_encode($array);
解决方案
我只是没有意识到我在脚本中仍然有两个echo
语句...这就是为什么它不被识别为JSON的原因./p>
I am trying to perform a GET
request and retrieve the data from the response.
this.http.get('http://localhost:8888/maneappback/more-items.php').subscribe(res => {
console.log(res.json());
}, (err) => {
console.log(err);
});
I am getting the error SyntaxError: Unexpected token C in JSON at position 0
. I am also assuming that the error is related to the request.
On my server side, I have the data being sent like this (PHP):
echo json_encode($array);
解决方案
I was just neglecting to realize that I still had two echo
statements in the script...that is why it wasn't recognized as JSON.
这篇关于SyntaxError:JSON位置0处出现意外的令牌C-Ionic 2 Http GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文