fromJSON(粘贴(raw.data,collapse=";)时出错:未关闭的字符串
我正在使用R包fromJSON(粘贴(raw.data,collapse=";)时出错:未关闭的字符串,json,r,Json,R,我正在使用R包rjson从Wunderground.com下载天气数据。我经常让程序运行,没有问题,数据收集得很好。但是,程序通常会停止运行,我会收到以下错误消息: Error in fromJSON(paste(raw.data, collapse = "")) : unclosed string In addition: Warning message: In readLines(conn, n = -1L, ok = TRUE) : incomplete final line foun
rjson
从Wunderground.com下载天气数据。我经常让程序运行,没有问题,数据收集得很好。但是,程序通常会停止运行,我会收到以下错误消息:
Error in fromJSON(paste(raw.data, collapse = "")) : unclosed string
In addition: Warning message:
In readLines(conn, n = -1L, ok = TRUE) :
incomplete final line found on 'http://api.wunderground.com/api/[my_API_code]/history_20121214pws:1/q/pws:IBIRMING7.json'
有人知道这意味着什么吗?我如何避免它,因为它会阻止我的程序按我的意愿收集数据
非常感谢,
Ben我可以使用
rjson
软件包重新创建您的错误消息
下面是一个有效的例子
rjson::fromJSON('{"x":"a string"}')
# $x
# [1] "a string"
如果我们从x
的值中省略了一个双引号,那么我们将得到错误消息
rjson::fromJSON('{"x":"a string}')
# Error in rjson::fromJSON("{\"x\":\"a string}") : unclosed string
RJSONIO
包的行为略有不同。它不会抛出错误,而是以静默方式返回NULL
值
RJSONIO::fromJSON('{"x":"a string}')
# $x
# NULL
您确定该包被称为来自JSON的
fromJSON
?rjson
和RJSONIO
软件包都有这个名字的函数,但是我找不到一个叫做这个名字的软件包。是的-对不起-你说得对。是rjson,小心点。您仍然需要检查任何NULL
值,并考虑如何处理它们。另一种方法是使用rjson
并将调用从json包装到try
或tryCatch
中。