【发布时间】:2016-03-01 17:06:02
【问题描述】:
假设我有以下 json 文件:
{
"id": "000018ac-04ef-4270-81e6-9e3cb8274d31",
"currentCompany": "",
"currentTitle": "--",
"currentPosition": ""
}
我使用以下代码:
Usersfile <- ('trial.json') #where trial the json above
library('rjson')
c <- file(Usersfile,'r')
l <- readLines(c,-71L)
json <- lapply(X=l,fromJSON)
我有以下错误:
Error: parse error: premature EOF
{
(right here) ------^
但是当我输入json文件(用记事本)并将数据放在一行中时:
{"id": "000018ac-04ef-4270-81e6-9e3cb8274d31","currentCompany": "","currentTitle": "--","currentPosition": ""}
代码工作正常。(实际上,文件非常大,需要手动为每一行执行)。为什么会这样?我该如何克服呢?
这个也不行:
{ "id": "000018ac-04ef-4270-81e6-9e3cb8274d31","currentCompany": "","currentTitle": "--","currentPosition": ""
}
编辑:我使用了以下代码,我只能读取第一个值:
library('rjson')
c <- file.path(Usersfile)
data <- fromJSON(file=c)
【问题讨论】: