我希望能够处理现在以JSON格式保存的数据。但是我对R非常陌生,对如何处理数据一无所知。您可以在下面看到我已经实现了什么。但首先,是我的代码:
library(rjson)
json_file <- "C:\\Users\\Saonkfas\\Desktop\\WOWPAPI\\wowpfinaljson.json"
json_data <- fromJSON(paste(readLines(json_file), collapse=""))
我成功获取了数据:
for (x in json_data){print (x)}
尽管输出看起来相当原始:
[[1]]
[[1]]$wins
[1] "118"
[[1]]$losses
[1] "40"
# And so on
请注意JSON数据有些嵌套。我可以使用Python创建表格,但似乎使用R更为复杂。
编辑:
我的JSON数据:
{
"play1": [
{
"wins": "118",
"losses": "40",
"max_killed": "7",
"battles": "158",
"plane_id": "4401",
"max_ground_object_destroyed": "3"
},
{
"wins": "100",
"losses": "58",
"max_killed": "7",
"battles": "158",
"plane_id": "2401",
"max_ground_object_destroyed": "3"
},
{
"wins": "120",
"losses": "38",
"max_killed": "7",
"battles": "158",
"plane_id": "2403",
"max_ground_object_destroyed": "3"
}
],
"play2": [
{
"wins": "12",
"losses": "450",
"max_killed": "7",
"battles": "158",
"plane_id": "4401",
"max_ground_object_destroyed": "3"
},
{
"wins": "150",
"losses": "8",
"max_killed": "7",
"battles": "158",
"plane_id": "2401",
"max_ground_object_destroyed": "3"
},
{
"wins": "120",
"losses": "328",
"max_killed": "7",
"battles": "158",
"plane_id": "2403",
"max_ground_object_destroyed": "3"
}
],
rjsonlite
еЊ…пјЊе…·дЅ“дїЎжЃЇиЇ·еЏ‚иЂѓиї™й‡Њпјљhttps://public.opencpu.org/posts/jsonlite-a-smarter-json-encoder/ - Stephen Henderson