用golang获取resJSON类型的变量res的errcode字段内容
假设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
原文地址: https://www.cveoy.top/t/topic/fuW8 著作权归作者所有。请勿转载和采集!