我有一个要转换为 json 格式的数据框:
我的数据框名为 res1:
library(rjson)
structure(list(id = c(1, 2, 3, 4, 5), value = structure(1:5, .Label = c("server1",
"server2", "server3", "server4", "server5"), class = "factor")), .Names = c("id",
"value"), row.names = c(NA, -5L), class = "data.frame")
当我做:
toJSON(res1)
我明白了:
{"id":[1,2,3,4,5],"value":["server1","server2","server3","server4","server5"]}
我需要这个json输出是这样的,有什么想法吗?
[{"id":1,"value":"server1"},{"id":2,"value":"server2"},{"id":3,"value":"server3"},{"id":4,"value":"server4"},{"id":5,"value":"server5"}]