我有以下代码:
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")
)