我正在尝试将以下JSON文件("my_file.json")读入R,其中包含以下内容:
[{"id":"484","comment":"They call me "Bruce""}]
Run Code Online (Sandbox Code Playgroud)
使用jsonlite包(0.9.12),以下操作失败:
library(jsonlite)
fromJSON(readLines('~/my_file.json'))
Run Code Online (Sandbox Code Playgroud)
收到错误:
"Error in parseJSON(txt) : lexical error: invalid char in json text.
84","comment":"They call me "Bruce""}]
(right here) ------^"
Run Code Online (Sandbox Code Playgroud)
这是R转义文件的输出:
readLines('~/my_file.json')
"[{\"id\":\"484\",\"comment\":\"They call me \"Bruce\"\"}]"
Run Code Online (Sandbox Code Playgroud)
删除"Bruce"周围的引号可以解决问题,如:
my_file.json
[{"id":"484","comment":"They call me Bruce"}]
Run Code Online (Sandbox Code Playgroud)
但是擒纵机构的问题是什么?