1

The below response is returned upon calling the signup function

Response {_body: "string(85) "{"message":"A customer with the same email 
already exists in an associated website."}"↵", status: 200, ok: true, 
statusText: "OK", headers: Headers, …}

headers: Headers {_headers: Map(1), _normalizedNames: Map(1)}
ok: true
status: 200
statusText: "OK"
type: 2
url: "http://127.0.0.1/sandbox/M2API/signup/signup"
_body: "string(85) "{"message":"A customer with the same email already exists in an associated website."}"↵"
__proto__: Body

Signup Function:

signup() {
this.authServiceProvider.postData(this.userData, "signup").then((result) => {
  this.responseData = result;
  console.log(this.responseData);
  if( (JSON.stringify(this.responseData._body)) != "" ) {
    this.navCtrl.setRoot(HomePage);
  } else {
    console.log("User already exists");
  }
}, (err) => {
  //connection failed error message
  console.log("something went wrong");
});
}

When i do console.log(JSON.stringify(this.responseData)); backslahes are added to json object

How to avoid that and access message in the response.

1

1 Answer 1

4

Use this

import 'rxjs/add/operator/map';

this.http.get('YOUR_API_ENDPOINT').map(res => res.json()).subscribe(data => {
      console.log(data);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.