Error while using body.json() for parsing response from http.get()

Samrat Das

Tried using body.json() to assign data to an array of object but as it returns a promise tried this. But browser throws error telling me json() is not a function.

getRecipes() {
  this.http.get('https://recipe-book-1be52.firebaseio.com/recipes.json').subscribe(
    (response: Response) => {
      response.json().then(
        (data) => {
          this.recServ.setRecipes(data)
        }
      );
    }
  )
}
Gauri Kesava Kumar

You can actually replace it like this, Also, can assign response to an interface to strict-type it.

getRecipes() {
  this.http.get('https://recipe-book-1be52.firebaseio.com/recipes.json').subscribe(
    (response) => this.recServ.setRecipes(response)
  );
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Get Response Code and Response Body ina a single request using Http-request

분류에서Dev

Getting error response while sending email from ionic using PHPMailer

분류에서Dev

How to get a response body while getting 403. Java

분류에서Dev

Getting NegativeArraySizeException while JSON parsing from openweathermap

분류에서Dev

Parsing nested JSON using body-parser and express

분류에서Dev

JSON HTTP response - get a single integer

분류에서Dev

Parsing twitter json response

분류에서Dev

get http response code from a url

분류에서Dev

Parsing JSON Response with Alamofire in Swift

분류에서Dev

ios JSON parsing error Error Domain = NSCocoaErrorDomain Code=3840 when uploading file and expecting response

분류에서Dev

android-async-http library get http response header from Response Handler

분류에서Dev

Android - Failure while parsing JSON

분류에서Dev

JSON Parsing error with Swift

분류에서Dev

jQuery - Error in parsing in JSON

분류에서Dev

Plug.Parser not reading/parsing JSON body

분류에서Dev

Nodejs Listening to response stream on data event from http.get()

분류에서Dev

Parsing JSON response gives null value

분류에서Dev

ParseUser JSON response error

분류에서Dev

How do I get a specific part from this JSON response?

분류에서Dev

How do I get a specific part from this JSON response?

분류에서Dev

parsing JSON object to get filelocation

분류에서Dev

Parsing JSON to Object using Jackson

분류에서Dev

Android Json Parsing Using GSON

분류에서Dev

Spring Boot RestController, On Error Status Response Body, Message of Error is empty

분류에서Dev

how to get attributes in output while convertin from xml to json?

분류에서Dev

json.decode(response.body)..."Here response.body is not working..."

분류에서Dev

How to get a total from JSON using Javascript

분류에서Dev

urllib.error.HTTPError : HTTP Error 404 : Not Found Python while scraping from Metacritic

분류에서Dev

Http Status 500 returned on Spring MVC Using REST Templates and JSON Response Format

Related 관련 기사

  1. 1

    Get Response Code and Response Body ina a single request using Http-request

  2. 2

    Getting error response while sending email from ionic using PHPMailer

  3. 3

    How to get a response body while getting 403. Java

  4. 4

    Getting NegativeArraySizeException while JSON parsing from openweathermap

  5. 5

    Parsing nested JSON using body-parser and express

  6. 6

    JSON HTTP response - get a single integer

  7. 7

    Parsing twitter json response

  8. 8

    get http response code from a url

  9. 9

    Parsing JSON Response with Alamofire in Swift

  10. 10

    ios JSON parsing error Error Domain = NSCocoaErrorDomain Code=3840 when uploading file and expecting response

  11. 11

    android-async-http library get http response header from Response Handler

  12. 12

    Android - Failure while parsing JSON

  13. 13

    JSON Parsing error with Swift

  14. 14

    jQuery - Error in parsing in JSON

  15. 15

    Plug.Parser not reading/parsing JSON body

  16. 16

    Nodejs Listening to response stream on data event from http.get()

  17. 17

    Parsing JSON response gives null value

  18. 18

    ParseUser JSON response error

  19. 19

    How do I get a specific part from this JSON response?

  20. 20

    How do I get a specific part from this JSON response?

  21. 21

    parsing JSON object to get filelocation

  22. 22

    Parsing JSON to Object using Jackson

  23. 23

    Android Json Parsing Using GSON

  24. 24

    Spring Boot RestController, On Error Status Response Body, Message of Error is empty

  25. 25

    how to get attributes in output while convertin from xml to json?

  26. 26

    json.decode(response.body)..."Here response.body is not working..."

  27. 27

    How to get a total from JSON using Javascript

  28. 28

    urllib.error.HTTPError : HTTP Error 404 : Not Found Python while scraping from Metacritic

  29. 29

    Http Status 500 returned on Spring MVC Using REST Templates and JSON Response Format

뜨겁다태그

보관