4
我需要動態構建以下JSON。如何使用嵌套列表構建JSON
{
"status": "SUCCESS",
"code": "200",
"output": {
"studentid": "1001",
"name": "Kevin"
}
}
我與jsonlite包嘗試過,但我無法構造內JSON對象。請幫我試着解決這個問題。
我需要動態構建以下JSON。如何使用嵌套列表構建JSON
{
"status": "SUCCESS",
"code": "200",
"output": {
"studentid": "1001",
"name": "Kevin"
}
}
我與jsonlite包嘗試過,但我無法構造內JSON對象。請幫我試着解決這個問題。
正如評論中所述,您可以創建一個嵌套列表並使用toJSON()
。
library(jsonlite)
x <- list(status = "SUCCESS", code = "200",
output = list(studentid = "1001", name = "Kevin"))
toJSON(x, pretty = TRUE, auto_unbox = TRUE)
這給下面的輸出:
{
"status": "SUCCESS",
"code": "200",
"output": {
"studentid": "1001",
"name": "Kevin"
}
}
我想你可以創建一個嵌套的列表,然後使用'toJSON'。 – Psidom