我正在尝试从R中展平嵌套的JSON文件,
这是我当前的代码
library(jsonlite)
json_file <- "json file"
json_data = fromJSON(json_file, flatten = FALSE)
flat_data = as.data.frame(json_data)
但是我遇到以下错误
flat_data = as.data.frame(json_data) 错误(函数(...,row.names = NULL,check.rows = FALSE,check.names = TRUE,: 参数意味着行数不同:1、13、3201
这是我的JSON结构的示例
{
"RIDE":{
"STARTTIME":"2020\/01\/05 22:27:49 UTC ",
"RECINTSECS":1,
"DEVICETYPE":"Garmin FR735XT ",
"IDENTIFIER":" ",
"TAGS":{
"Aerobic Training Effect":"3.8 ",
"Athlete":"Chuck Finley",
"Data":" ",
"Device":"Garmin",
"Device Info":"HR Garmin 2327",
"File Format":" ",
"Filename":"2020_01_06_06_27_49.json ",
"Month":"January ",
"Performance Condition":"-5 ",
"Recovery Time":" ",
"Source Filename":"A1662750_2020_01_06_06_27_49.gz ",
"Sport":"Run ",
"SubSport":" ",
"VO2max detected":"61.7 ",
"Weekday":"Mon ",
"Workout Code":" ",
"Year":"2020 "
},
"INTERVALS":[
{ "NAME":"Lap 1 ", "START": 0, "STOP": 249, "COLOR":"#000000", "PTEST":"false" },
{ "NAME":"Lap 2 ", "START": 250, "STOP": 504, "COLOR":"#000000", "PTEST":"false" }
],
"SAMPLES":[
{ "SECS":0, "KM":0, "KPH":0, "HR":104, "ALT":14, "LAT":-40.402758436, "LON":175.0371112, "SLOPE":0, "LRBALANCE":0, "RCAD":109.5, "RVERT":0.47, "RCON":273 },
{ "SECS":1, "KM":0.00056, "KPH":0, "HR":104, "ALT":14, "LAT":-40.402758436, "LON":175.0371112, "SLOPE":0, "LRBALANCE":24.87, "RCAD":109.5, "RVERT":0.47, "RCON":273 }
],
"XDATA":[
{
"NAME" : "EXTRA",
"VALUES" : [ "STANCETIMEPERCENT", "VERTICALRATIO", "STEPLENGTH", "FIELD_88", "ACTIVITYTYPE", "PERFORMANCECONDITION" ],
"UNITS" : [ "", "", "", "", "", "" ],
"SAMPLES" : [
{ "SECS":1, "KM":0, "VALUES":[ 48.5, 0, 0, 300, 1, 0 ] },
{ "SECS":2, "KM":0, "VALUES":[ 48.5, 4.96, 891, 300, 1, 0 ] }
]
}
]
}
}
我对R相当陌生,因此不胜感激。
答案 0 :(得分:0)
只需更改文件名。 Json文件应为 .json
json_file <- "json file.json"