我有一个数据框,想将其转换为JSON格式:
我的数据框叫做res1:
我的数据框叫做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"}]
第20行解析错误: ... 5, "value:"server5"}] ----------------------^ 期望 '}', ':', ',', ']'
- doctorlove