對象由as.tbl_json
產生有點奇怪我的思維方式,與一個單一項目的名稱,document.id
,值爲1.它的屬性之一叫JSON
:
json <- '
[{"country":"us","city":"Portland","topics":[{"urlkey":"videogame","name":"Video Games","id":4471},{"urlkey":"board-games","name":"Board Games","id":19585},{"urlkey":"computer-programming","name":"Computer programming","id":48471},{"urlkey":"opensource","name":"Open Source","id":563}],"joined":1416349237000,"link":"http://www.meetup.com/members/156440062","bio":"Analytics engineer. Primarily work in the Hadoop space.","lon":-122.65,"other_services":{},"name":"Aaron Wirick","visited":1443078098000,"self":{"common":{}},"id":156440062,"state":"OR","lat":45.56,"status":"active"}]
'
obj <- json %>% as.tbl_json
> dput(obj)
structure(list(document.id = 1L), .Names = "document.id", row.names = 1L, class = c("tbl_json",
"tbl", "data.frame"), JSON = list(list(structure(list(country = "us",
city = "Portland", topics = list(structure(list(urlkey = "videogame",
name = "Video Games", id = 4471L), .Names = c("urlkey",
"name", "id")), structure(list(urlkey = "board-games", name = "Board Games",
id = 19585L), .Names = c("urlkey", "name", "id")), structure(list(
urlkey = "computer-programming", name = "Computer programming",
id = 48471L), .Names = c("urlkey", "name", "id")), structure(list(
urlkey = "opensource", name = "Open Source", id = 563L), .Names = c("urlkey",
"name", "id"))), joined = 1416349237000, link = "http://www.meetup.com/members/156440062",
bio = "Analytics engineer. Primarily work in the Hadoop space.",
lon = -122.65, other_services = structure(list(), .Names = character(0)),
name = "Aaron Wirick", visited = 1443078098000, self = structure(list(
common = structure(list(), .Names = character(0))), .Names = "common"),
id = 156440062L, state = "OR", lat = 45.56, status = "active"), .Names = c("country",
"city", "topics", "joined", "link", "bio", "lon", "other_services",
"name", "visited", "self", "id", "state", "lat", "status")))))
看,你可以看到,爲了獲得在嵌入列表對象的名稱,那就是屬性的,你需要做的這個值:
names(attr(obj, "JSON")[[1]][[1]])
#------------
[1] "country" "city" "topics" "joined" "link"
[6] "bio" "lon" "other_services" "name" "visited"
[11] "self" "id" "state" "lat" "status"
希望我能更多的幫助,但至少你明白錯誤來自哪裏。 (我也希望在該包的幫助頁面上有更多示例。)
從哪裏來'%>%'? –
@pascal - 當然是dplyr – thelatemail
@Pascal - 它在標題中 - 'tidyjson'包 – thelatemail