简体   繁体   English

离子 3 中 position 1 的 JSON 中的意外令牌 o

[英]Unexpected token o in JSON at position 1 in ionic 3

I am working on ionic 3 app.我正在开发 ionic 3 应用程序。 when i run it on browser its working fine but when i run as a apk or on mobile it gives me error 'Unexpected token o in JSON at position 1' as shown in screenshot https://prnt.sc/q0jxlf . when i run it on browser its working fine but when i run as a apk or on mobile it gives me error 'Unexpected token o in JSON at position 1' as shown in screenshot https://prnt.sc/q0jxlf . i dont know why its occuring in apk while its working accurately on browser siple ionic serve run.this is my code我不知道为什么它在 apk 中出现,而它在浏览器 siple ionic serve run 上准确工作。这是我的代码

register(user)
{
    return new Promise(resolve => {debugger;

        this.http.post(global.apiUrl + "register", user.value)


            // .map(res => res.json())
              .subscribe(data => {debugger;
                this.data = data;
                resolve(this.data);
            },error =>{debugger;
                let jsonE = JSON.parse(error._body);

                    let alert = this.alertCtrl.create({
                        title: 'Error!',
                        subTitle:jsonE.error,
                        buttons: ['OK']
                    });
                    alert.present();

                }
            );
    });

please help me i am musch confused请帮帮我,我很困惑

I've actually had a similar issue to this and it seems what I did solved the issue.我实际上遇到了与此类似的问题,看来我所做的事情解决了这个问题。 The angular Http Client returns an error object that includes and error and message property. angular Http 客户端返回错误 object,其中包括错误和消息属性。 I used those to display to the user for errors, but in cases of submission timeouts or disconnections during the submissions my backend would spit out a different error not caught by the Http client.我使用这些向用户显示错误,但在提交期间提交超时或断开连接的情况下,我的后端会吐出 Http 客户端未捕获的不同错误。

 error =>{debugger; let jsonE = 'Uncaught Error;'. if(error._body.= undefined){ let err = JSON;parse(error._body). jsonE = err.error } let alert = this:alertCtrl,create({ title: 'Error,': subTitle; jsonE. buttons; ['OK'] }); alert.present(); }

I would probably go as far as adding a try, catch block inside wrapped around your error handling because it seems that the error body is inconsistent.我可能会 go 就添加一个 try, catch 块来包裹你的错误处理,因为看起来错误主体是不一致的。

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

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