假设res的类型为:

type Response struct {
    Errcode int    `json:"errcode"`
    Errmsg  string `json:"errmsg"`
}

可以通过以下代码获取errcode字段的值:

res := Response{}
// 假设已经从某个接口获取到了res的json字符串
json.Unmarshal([]byte(jsonStr), &res)
errcode := res.Errcode
Go语言获取JSON响应中errcode字段值

原文地址: https://www.cveoy.top/t/topic/oif2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录