r - 将 JSON 从文件读取到 tidyjson
问题描述
我正在尝试从下面的位置读取 json 并使用 tidyjson 创建一个整洁的版本。
https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json
tidyjson 的指南没有提到如何读取文件。我尝试了各种方法,包括 fromJSON、read_JSON、readJSON 和 read_lines,但在每个示例中都遇到了错误。
例如
peopleJSON <- read_lines(url("https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json"))
people <- peopleJSON %>% as.tbl_json
Error: parse error: premature EOF
{
(right here) ------^
我不确定我是否做错了什么或者问题是否与数据有关。
任何帮助都将受到热烈欢迎。
解决方案
fromJSON
fromjsonlite
返回 4 个数据帧的列表。
data <- jsonlite::fromJSON('https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json')
sapply(data, dim)
# memberships organizations persons posts
#[1,] 45674 43 13902 2370
#[2,] 15 4 5 8
data$memberships
您可以使用等访问单个数据框data$organizations
。
推荐阅读
- javascript - 如何将网站访问者重定向到随机网址
- javascript - Javascript 禁用 chrome 通知
- javascript - 如何将 JavaScript 变量传递给 PHP 变量?
- batch-file - 在cmd/batch中逐个字符循环字符串?
- angular - 带有粘性和自定义宽度列的角材料表
- php - laravel 与关系回调函数并加入它
- vb.net - IsNumeric 语句和范围
- python - 如何切片具有“无”维度的张量?
- excel - 基于部分字符串的 SUMIF
- qt - QT QPainter 在 QPixmap 上绘制,坐标在像素图之外