2 回答
TA贡献1827条经验 获得超9个赞
请求主体不一样:
在 curl 中,您发送 {"inputs": [{"desc":"program","ind":"14","p":"program"}]}
在 go 中,您将inputs=%7B%22desc%22%3A%22program%22%2C%22ind%22%3A%2214%22%2C%22p%22%3A%22program%22%7D哪些 URLDecodes发送到inputs={"desc":"program","ind":"14","p":"program"}.
所以,你可能应该做的是这样的:
type body struct {
Inputs []input `json:"input"`
}
type input struct {
Desc string `json:"desc"`
Ind string `json:"ind"`
P string `json:"p"`
}
然后创建一个body:
b := body{
Inputs: []input{
{
Desc: "program",
Ind: "14",
P: "program"},
},
}
编码:
q, err := json.Marshal(b)
if err != nil {
panic(err)
}
你显然不应该恐慌,这只是为了演示。不管怎样,一个string(q)会得到你{"input":[{"desc":"program","ind":"14","p":"program"}]}。
在操场上试一试
- 2 回答
- 0 关注
- 132 浏览
添加回答
举报