语法错误:JSON 中位置 0 的意外标记 C - Ionic 2 Http GET 请求 [英] SyntaxError: Unexpected token C in JSON at position 0 - Ionic 2 Http GET request

查看:24
本文介绍了语法错误:JSON 中位置 0 的意外标记 C - Ionic 2 Http GET 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行 GET 请求并从响应中检索数据.

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);
});

我收到错误 SyntaxError: Unexpected token C in JSON at position 0.我还假设错误与请求有关.

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.

在我的服务器端,我有这样发送的数据(PHP):

On my server side, I have the data being sent like this (PHP):

echo json_encode($array);

推荐答案

我只是忽略了我在脚本中仍然有两个 echo 语句......这就是为什么它不是识别为 JSON.

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.

这篇关于语法错误:JSON 中位置 0 的意外标记 C - Ionic 2 Http GET 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆