以下结构体为例子,请结合自己的进行改造
type RegisterRequest struct {
Account string `json:"Account" doc:"用户名称"`
UserPassword string `json:"UserPassword" doc:"用户密码"`
Mobile string `json:"Mobile" doc:"手机号"`
Code string `json:"Code" doc:"短信验证码"`
VerificationCode string `json:"Code" doc:"风险验证码"`
}
// 转成字符串,req为接收的JSON
accessTokenJSON, _ := json.Marshal(req)
// 解码JSON字符串为Go对象
var tokenInfo RegisterRequest
err = json.Unmarshal([]byte(v), &tokenInfo)
if err != nil {
fmt.Println("Error decoding JSON:", err)
return
}
// 将Go对象重新编码为JSON字符串
newAccessTokenJSON, err := json.Marshal(tokenInfo)
if err != nil {
fmt.Println("Error encoding JSON:", err)
return
}
fmt.Println(newAccessTokenJSON["Account"].(string))