【发布时间】:2017-10-06 16:35:48
【问题描述】:
我在 R 中的 RJSONIO 包中的 fromJSON 函数有问题。
我有一个 json 文件可以用 fromJSON 读取
{"indy movies" :[
{
"name" : "Raiders of the Lost Ark",
"year" : 1981,
"actors" : {
"Indiana Jones": "Harrison Ford",
"Dr. René Belloq": "Paul Freeman"
},
"producers": ["Frank Marshall", "George Lucas", "Howard Kazanjian"],
"budget" : 18000000,
"academy_award_ve": true
},
{
"name" : "Indiana Jones and the Temple of Doom",
"year" : 1984,
"actors" : {
"Indiana Jones": "Harrison Ford",
"Mola Ram": "Amish Puri"
},
"producers": ["Robert Watts"],
"budget" : 28170000,
"academy_award_ve": true
},
{
"name" : "Indiana Jones and the Last Crusade",
"year" : 1989,
"actors" : {
"Indiana Jones": "Harrison Ford",
"Walter Donovan": "Julian Glover"
},
"producers": ["Robert Watts", "George Lucas"],
"budget" : 48000000,
"academy_award_ve": false
}]}
文件名为“indy.json”
这是一个可重现的例子:
indy <- fromJSON(content = "indy.json")
但是,我得到了结果:
> indy <- fromJSON(content = "indy.json")
Error in nchar(content) : invalid multibyte string, element 1
这是我的相关 sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4
谁能说明为什么会这样?
【问题讨论】:
-
我也使用 Mac、W.david,您的代码对我来说运行良好。您是否在 Atom 或 Sublime Text 等文本编辑器中打开了 JSON 文件以检查是否有 NULL 或类似的东西?这些多字节错误通常来自文件中某种类型的异常字符,例如`ñ`等。