gpt4 book ai didi

go - 如何使用多个JSON对象触发和处理http POST请求

转载 作者:行者123 更新时间:2023-12-01 21:12:26 28 4
gpt4 key购买 nike

我正在尝试通过以下更改来实现Go代码。
使用Go发送带有多个JSON对象的http POST请求,并在响应中处理相同的请求。
以下是我编写的示例代码。

type ReqData struct {
Status string `json:"status"`
Ok string `json:"ok"`
}

type RespData struct {
Name string `json:"name"`
Number string `json:"number"`
}

type RespData1 struct {
Employee string `json:"employee"`
Service string `json:"service"`
}

type FullResponse struct {
FullResponse RespData `json:"candidate"`
FullResponse1 RespData1 `json:"employees"`
}

func POST(c *gin.Context) {
respData := FullResponse{}

str := RespData{"2222222222", "2222222222"}
respData.FullResponse = str
b, _ := json.Marshal(respData)
respbody1 := string(b)

respData1 := FullResponse{}
str1 := RespData1{"111111111111111", "111111"}
respData1.FullResponse = str1
c, _ := json.Marshal(respData1)
respbody2 := string(c)

respbody := respbody1 + respbody2
c.String(http.StatusOK, respbody)

}

最佳答案

您可以发出如下请求类型:

    type requestType struct {
AuthReq1 *authReq1 `json:"auth_req1"`
AuthReq2 *authReq2 `json:"auth_req2"`
}
现在发布并处理requestType。
祝好运!

关于go - 如何使用多个JSON对象触发和处理http POST请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63462807/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com