【问题标题】:jsonlite suddenly retunring error: "Failure when receiving data from the peer"jsonlite突然返回错误:“从对端接收数据失败”
【发布时间】:2018-07-09 14:28:00
【问题描述】:

突然,在周末,我的代码不再工作。

当我运行它时,我收到以下消息:

parse_con(txt, bigint_as_char) 中的错误: 接收对端数据失败

代码如下:

raiz      <- "https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/odata/"
tipo      <- "ExpectativaMercadoMensais?%24format=json&%24select="
indicador <- "Indicador,Data,DataReferencia,Mediana,numeroRespondentes"
restricao <- "&%24orderby=Data%20desc&%24filter=Indicador%20eq%20'IPCA'&%24top=10"

library("jsonlite")
jsonlite::fromJSON(paste0(raiz,tipo,indicador,restricao), simplifyVector = FALSE)

【问题讨论】:

  • 这很奇怪,但它正在使用 rjson

标签: r jsonlite


【解决方案1】:

jsonlite用来读取网站的GET函数有问题。请改用readLines

raiz      <- "https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/odata/"
tipo      <- "ExpectativaMercadoMensais?%24format=json&%24select="
indicador <- "Indicador,Data,DataReferencia,Mediana,numeroRespondentes"
restricao <- "&%24orderby=Data%20desc&%24filter=Indicador%20eq%20'IPCA'&%24top=10"

library("jsonlite")
web <- readLines(paste0(raiz,tipo,indicador,restricao), warn = FALSE)
df <- jsonlite::fromJSON(web, simplifyVector = FALSE)

我没听懂您的问题,但我们有一个可行的方法:

web <- readLines("https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/odata/ExpectativasMercadoInflacao12Meses?$format=json", warn = FALSE)
df <- fromJSON(web)
df$value   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-27
    • 2019-01-03
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多