JSON 数据前面的正斜杠

forward slashes at the front of JSON data

这是对加拿大统计局 JSON 数据文件的请求;它是新 Web 数据服务的示例 URL。

当我尝试通过 rjson 获取文件时,我收到关于意外字符的错误

Error in fromJSON(file = census_url) : unexpected character 
'/'

这是示例代码

   #install.packages('rjson')
   library(rjson)
   #This is the sample URL from your web data help page. 
   census_url<-'https://www12.statcan.gc.ca/rest/census- 
   recensement/CPR2016.json? 
   lang=E&dguid=2016A000011124&topic=1&notes=0'
   #This returns an unexpected character
   fromJSON(file=census_url)

当我在 一个 JSON 格式化程序中输入这个 URL 时,我得到指向两个正斜杠的错误。

当我查看 JSON 文档 link 时,似乎正斜杠用作注释字符。

所以,这是加拿大统计局的问题吗?或者 R 内部是否有解决方法来正确解析此数据?

在将其传递给fromJSON之前,我们可能会加载文件并删除前两个字符:

fromJSON(json_str = substring(readLines(census_url), 3))