在 R 中使用 jsonlite 时,如何手动指定哪些被视为数组?在这种情况下,auto_unbox不起作用



我有以下代码:

data = list(
"id" = equip_id,
"initial_date" = 1608433200,
"final_date" = 1609038000,
"limit" = 10000,
"order" = "asc",
"properties" = "forecast"
)

如果我使用:

jsonlite::toJSON(data, auto_unbox = TRUE)

我有这个:

{"id":3,"initial_date":1608433200,"final_date":1609038000,"limit":10000,"order":"asc","properties":"forecast"} 

但我想要的是:

{"id":3,"initial_date":1608433200,"final_date":1609038000,"limit":10000,"order":"asc","properties":["forecast"]} 

如何手动编辑哪些是数组?

properties转换为列表:

data = list(
"id" = equip_id,
"initial_date" = 1608433200,
"final_date" = 1609038000,
"limit" = 10000,
"order" = "asc",
"properties" = list("forecast")
)

相关内容

  • 没有找到相关文章

最新更新