given the following R code:
library(rjson)
x <- c(3:5)
toJSON(x)
it produces:
[1] "[3,4,5]"
when I am expecting something like:
"[3,4,5]"
I am a new to 开发者_开发问答R, I guess this is something easy to do, but I had have no luck finding a solution.
I believe that [1] is just the R Console's output indicating that "[3,4,5]" is the first element in that vector. The actual result stored is in fact "[3,4,5]". Try this:
cat(toJSON(x))
So, for instance, if you stored the JSON result in a new variable, and passed it on to something else, the '[1]' doesn't ride along, just the part you want. It's only for display purposes in the console.
精彩评论