如何删除反斜杠以响应 R 中的 jsonlite?
How remove backslashes in response for jsonlite in R?
我有以下用于 R Plumber API 服务器的代码
library(jsonlite)
library(data.table)
#' Home endpoint
#' @get /
function(){
df <- data.table(msg = "Welcome")
toJSON(df)
}
它在 API 上给了我 ["[{\"msg\":\"Welcome\"}]"]
结果。
如何在浏览器或 Postman 中替换 \" on " 符号以使其更人性化?预期结果是 "msg":"Welcome".
谢谢!
plumber
已经对它进行了 jsonifies,你正在加倍它。试试这个:
#' Home endpoint
#' @get /
function(){
df <- data.table::data.table(msg = "Welcome")
return(df)
}
然后在我的控制台中,我 运行:
pr <- plumber::plumb("~/Whosebug/4393334/60918243.R")
pr$run()
# Starting server to listen on port 5225
# Running the swagger UI at http://127.0.0.1:5225/__swagger__/
然后在我的 bash shell:
$ curl -s localhost:5225
[{"msg":"Welcome"}]
我有以下用于 R Plumber API 服务器的代码
library(jsonlite)
library(data.table)
#' Home endpoint
#' @get /
function(){
df <- data.table(msg = "Welcome")
toJSON(df)
}
它在 API 上给了我 ["[{\"msg\":\"Welcome\"}]"]
结果。
如何在浏览器或 Postman 中替换 \" on " 符号以使其更人性化?预期结果是 "msg":"Welcome".
谢谢!
plumber
已经对它进行了 jsonifies,你正在加倍它。试试这个:
#' Home endpoint
#' @get /
function(){
df <- data.table::data.table(msg = "Welcome")
return(df)
}
然后在我的控制台中,我 运行:
pr <- plumber::plumb("~/Whosebug/4393334/60918243.R")
pr$run()
# Starting server to listen on port 5225
# Running the swagger UI at http://127.0.0.1:5225/__swagger__/
然后在我的 bash shell:
$ curl -s localhost:5225
[{"msg":"Welcome"}]