R-fromJSON(raw.data)中的错误:不完整的列表 [英] R - Error in fromJSON(raw.data) : incomplete list
本文介绍了R-fromJSON(raw.data)中的错误:不完整的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将BLS中的API数据读取到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
如果我只是尝试转到Webrowser中的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屋!
查看全文