当将字符串作为我的plumber.R响应的一部分时,它们总是封装在列表中,即使在列表中只有单个字符串而不是多个字符串的情况下,尤其如此。
我知道这就是R通常看起来如何处理字符串的方式,如下所示
> list(response = "This is my text")
$response
[1] "This is my text"
但是我不确定如何在Plumber中操纵输出以在json响应中获取所需的格式。
我的代码
library("plumber")
#* returns a fixed string
#* @get /mytext
get_mytext <- function(req,res) {
return(list(response = "This is my text"))
}
预期产量
{
"response": "This is my text"
}
实际输出
{
"response": [
"This is my text"
]
}