R中是否有一种方法可以将逗号添加到不正确的JSON格式?

时间:2019-12-07 02:35:18

标签: r json jsonlite

我正在尝试在R中使用JSON文件,但是不幸的是,JSONlite在当前状态下无法读取JSON文件。对象(数组元素?)之间缺少逗号。我的目标是从几乎是JSON的文件中形成一个数据框架。以下是示例JSON文件,代码和结果。

[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450} 
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
]

> jsondata = fromJSON("asdf.json")
Error in parse_con(txt, bigint_as_char) : 
  parse error: after array element, I expect ',' or ']'
          "Heading":280,"Speed":124}   {"Source":"ADSB","Id":43062,"Fl
                     (right here) ------^

在JSON文件中的对象之间插入逗号后,它没有问题。

[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}, 
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
]
> jsondata = fromJSON("asdf.json")
> names(jsondata)
[1] "Source"    "Id"        "FlightId"  "Latitude"  "Longitude" "Alt" 

如何在所有弯曲括号之间的整个JSON文件中插入逗号? (即“} {”->“},{” 还是R有另一种方式读取我不完整的JSON文件?

我还不是新手,所以非常感谢您的帮助!

0 个答案:

没有答案