R - fromJSON(raw.data) 中的错误:列表不完整 [英] R - Error in fromJSON(raw.data) : incomplete list

查看:36
本文介绍了R - fromJSON(raw.data) 中的错误:列表不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 API 数据从 BLS 读取到 R.我使用的是 1.0 版,该版本不需要注册且已开放供公众使用.

I'm trying to read API data from the BLS into R. I am using the Version 1.0 that does not require registration and is open for public use.

这是我的代码:

url <-"http://api.bls.gov/publicAPI/v1/timeseries/data/LAUCN040010000000005"
raw.data <- readLines(url, warn = F)

library(rjson)

rd <- fromJSON(raw.data)

这是我收到的错误消息:

And here is the error message I receive:

Error in fromJSON(raw.data) : incomplete list

如果我只是尝试转到我的网络浏览器中的 url,它似乎可以工作(拉出一个 JSON 网页).当我尝试将其导入 R 时,我不太确定发生了什么.

If I just try to go to the url in my webrowser it seems to work (pull up a JSON webpage). Not really sure what is going on when I try to get this into R.

推荐答案

当你使用 readLines 时,返回的对象是一个长度为 4 的向量:

When you've used readLines, the object returned is a vector of length 4:

length(raw.data)

您可以通过以下方式查看各个部分:

You can look at the individual pieces via:

raw.data[1]

如果你使用 paste

fromJSON(paste(raw.data, collapse = ""))

一切正常.或者,

jsonlite::fromJSON(url)

这篇关于R - fromJSON(raw.data) 中的错误:列表不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆