R create JSON in R

2019-08-12 19:50发布

I want to get to get the values from this JSON string: { "item": [ { "value": 142 } , { "value": 200 } ] }

R code:

library(rjson)
item <- list(item=c(value= 142,value=200))
toJSON(item)

And I have:

> toJSON(item)
[1] "{\"item\":{\"value\":142,\"value\":200}}"

How do I get the values from the json string in R?

标签: r rjson
1条回答
男人必须洒脱
2楼-- · 2019-08-12 20:36

Discussion of I() and what it does is in the RJSONIO documentation, but that's what you are looking for...

library("RJSONIO")
item <- list(item=I(list(list(value= 142),list(value=200))))
> toJSON(item)
[1] "{\n \"item\": [\n {\n \"value\":    142 \n},\n{\n \"value\":    200 \n} \n] \n}"
查看更多
登录 后发表回答