小编ztp*_*ztp的帖子

不带外部方括号的 toJSON

我正在使用 jsonlite 中的 toJSON() 将特定结构(API 所需)的嵌套列表转换为 JSON。但是,我需要最终的 JSON 不包含外部方括号(API 也需要)。

test_list <- list(
    list(formName = "test_title", user_id = "test_userid", rows = list(list(row = 0))), 
    list(formName = "test_title2", user_id = "test_userid2", rows = list(list(row = 0)))
)

jsonlite::toJSON(test_list, pretty = TRUE, auto_unbox = TRUE)
Run Code Online (Sandbox Code Playgroud)

这使:

[
  {
    "formName": "test_title",
    "user_id": "test_userid",
    "rows": [
      {
        "row": 0
      }
    ]
  },
  {
    "formName": "test_title2",
    "user_id": "test_userid2",
    "rows": [
      {
        "row": 0
      }
    ]
  }
] 
Run Code Online (Sandbox Code Playgroud)

但我需要删除第一个和最后一个方括号。

我可以使用 purrr::flatten() 删除列表的顶层,从而删除 JSON 中的方括号,但 toJSON() 似乎不喜欢列表有重复的名称,并将它们重命名为 …

r jsonlite purrr

5
推荐指数
2
解决办法
3303
查看次数

fileInput 中进度条的颜色 -- Shiny

我正在尝试更改 Shiny 中 fileInput 小部件中上传进度条的颜色。我是一个有点闪亮的新手,在互联网上搜索过但没有结果。有任何想法吗?

r shiny

2
推荐指数
1
解决办法
2453
查看次数

标签 统计

r ×2

jsonlite ×1

purrr ×1

shiny ×1