2

I'm trying to update a project from March 2018. Previously, I had used

library("httr")
library("rjson")
api.url <- "http://api.tvmaze.com/lookup/shows?imdb=tt1325113"
response <- GET(api.url)
response.list <- fromJSON(content(response))

Previously, this returned a list containing the parsed json information that I used sapply to extract the relevant information from. Now, it's showing

Error in UseMethod("content", x) : 
  no applicable method for 'content' applied to an object of class "response"

There appears to be some kind of change in the httr package but I can't figure out what it is. Any ideas of what might be different and how to get around it?

Jamie B
  • 23
  • 2
  • Does `content(response)` return what you want without the `fromJSON`? The response has a content type of "application/json" so the `content()` should automatically parse the JSON for you. I tested with `httr_1.4.0` and it worked fine. – MrFlick May 28 '19 at 18:30

2 Answers2

1

You have to specify the as argument of content, the code below should do the trick.

library("httr")
library("rjson")
api.url <- "http://api.tvmaze.com/lookup/shows?imdb=tt1325113"
response <- GET(api.url)

response.list <- 
  fromJSON(content(response, as = "text"))
Noah Olsen
  • 271
  • 1
  • 14
0

It is most likely a pkg conflict issue only, make sure you reference the pkg name:

httr::content(response)

That because some pkgs use same function name, like NLP::content(). Hope this will help in your case.