Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fromJSON(粘贴(raw.data,collapse=";)时出错:未关闭的字符串_Json_R - Fatal编程技术网

fromJSON(粘贴(raw.data,collapse=";)时出错:未关闭的字符串

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

我正在使用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 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
中。