具有字符数据的键值对到 R 中的数据框?

Key-value pairs with character data to a dataframe in R?

我一直在 了解如何使用 rjson 将键值字典转换为 R 中的数据框,但我似乎无法让它与我的数据一起使用:

{"tagid":493,"name":"Early Access","count":75}
{"tagid":599,"name":"Simulation","count":68,"browseable":true}
{"tagid":1755,"name":"Space","count":64,"browseable":true}

由于 name 键的字符值,似乎不想解析为数据帧:

Error in FUN(X[[i]], ...) : unexpected character '''

我使用的代码与我链接到的示例相同:

library(rjson)
Lines <- readLines("clipboard") 
json_df <- as.data.frame(t(sapply(Lines, fromJSON)))

如果有字符数据,这里有没有办法将字典数据类似地转换为数据框?

编辑:以下脚本是我用来生成数据的脚本:

webpage <- read_html("https://store.steampowered.com/app/387290")
data <- html_nodes(webpage, css = "script") %>% html_text()

tag_data <- data[lapply(data,function(x) length(grep("InitAppTagModal",x,value=FALSE))) == 1]
tag_data <- regmatches(tag_data, gregexpr("[?<=\[].*?[?=\]]", tag_data, perl=T))[[1]][1]
tag_data <- gsub('[', "", tag_data, fixed = TRUE)
tag_data <- gsub(']', "", tag_data, fixed = TRUE)
tag_data <- gsub("},{", "}\n{", tag_data, fixed = TRUE)

writeLines(tag_data, con = "temp.json", sep = "\n")
tag_df <- stream_in(file("temp.json"))

我将您的示例数据放入 json 文件中。我将其命名为 test.json

library(jsonlite)

myoutput <- stream_in(file("test.json"))
myoutput

  tagid         name count browseable
1   493 Early Access    75         NA
2   599   Simulation    68       TRUE
3  1755        Space    64       TRUE