简体   繁体   English

SyntaxError:JSON中位置0上的意外令牌<

[英]SyntaxError: Unexpected token < in JSON at position 0

SyntaxError: Unexpected token < in JSON at position 0 SyntaxError:JSON中位置0上的意外令牌<

while retrieving json data using ionic 2 here is the link http://areeef.unaux.com/php/platforms.php 使用ionic 2检索json数据时,此处是链接http://areeef.unaux.com/php/platforms.php

here is the code i am using to get json data 这是我用来获取json数据的代码

constructor( public navCtrl: NavController, private http: Http) {

this.http.get('http://areeef.unaux.com/php/platforms.php').map(res => res.json()).subscribe(data => {
   console.log(data);
}); }

when i run the same php code in local host then i can run the app without any error. 当我在本地主机上运行相同的PHP代码时,我可以运行该应用程序而不会出现任何错误。 but in online sever it is giving the error mentioned above so is that a problem of the server or error in my code? 但是在在线服务器中,它给出了上面提到的错误,那么这是服务器问题还是我的代码错误?

Nothing seems wrong with the code. 代码似乎没有错。 The problem is because your server not returning valid JSON. 问题是因为您的服务器未返回有效的JSON。

Check the API's behaviour using postman plugin. 使用邮递员插件检查API的行为。 I have checked it and it returning invalid JSON- 我检查了它,并返回了无效的JSON-

This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support 本网站需要使用Javascript,请在​​浏览器中启用Javascript或使用支持Javascript的浏览器

So, get your api working on postman first. 因此,首先让您的api在邮递员上工作。

This error is normally caused by the server returning non JSON data. 此错误通常是由服务器返回非JSON数据引起的。 In this case, the PHP script could be returning an error message in form of HTML which will cause an error. 在这种情况下,PHP脚本可能会以HTML形式返回错误消息,这将导致错误。 The best approach for such errors is to debug the PHP script independently or accommodate the possibility of getting both html and JSON data on the client side. 解决此类错误的最佳方法是独立调试PHP脚本,或者容纳在客户端获取html和JSON数据的可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM