Steven Ng
Steven Ng

Reputation: 25

Unexpected token < in JSON at position 1 ----ionic3

The data can be inserted into the database and the JSON also can be generated very well but why is 'Unexpected token < in JSON at position 1' thrown?

The problem has been shown in the picture

problem has been shown in picture

signup.ts

signup(){
     this.authService.postData(this.userData,'signup').then((result) => {
      this.responseData = result;
      if(this.responseData.userData){
      console.log(this.responseData);
      localStorage.setItem('userData', JSON.stringify(this.responseData));
      this.navCtrl.push(LoginPage);
      }
      else{ {swal({
        title: "User already exist.Please try again",
         })
         } }
    }, (err) => { ;
      // Error log
    });

}

Upvotes: 0

Views: 136

Answers (2)

Chintan Dave
Chintan Dave

Reputation: 11

You can validate JSON response in your service by using rxjs map operater:

this.http.get(YOUR_URL).map(res => res.json());

Upvotes: 0

coder_strange
coder_strange

Reputation: 298

You're getting BR tag in your response, and because of that it can't be parsed to JSON, so remove the

>  <br />[email protected]

tag from your response.

Upvotes: 1

Related Questions