may
may

Reputation: 79

How do I get a JSON object from an Http Response?

I have the following api call in my service:

    getData()  {
    return this.http.post<Object>(this.base_URL + "web_app/login/", JSON.stringify(this.login))

  .subscribe(response=>{    
    console.log(response);

  })

The response is an object with two attributes, access_token and Success. I get the following in my console:

{access_token: "...", Success: "Success"}
Success: "Success"
access_token:"..."

When I try to access the access_token attribute, using response.access_token, I get an error. Why is this and how do I fix it? Is the response I'm getting an object? Thank you!

Edit: this is what console gives enter image description here

Upvotes: 0

Views: 5168

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222722

As your image shows you are getting the response on console, try accessing it as follows,

.subscribe(response=>{    
    console.log(response['access_token']);
  })

Upvotes: 2

Related Questions