[Go] json.Unmarshal()解析后存储的结构体定义

前端之家收集整理的这篇文章主要介绍了[Go] json.Unmarshal()解析后存储的结构体定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

按照文档要求

bool,for JSON booleans

 float64,for JSON numbers

 string,for JSON strings

 []interface{},for JSON arrays

 map[string]interface{},for JSON objects

 nil for JSON null

 

对于json中的booleans 会解析结构体字段类型为 bool类型

对于json中的数字 会解析结构体字段类型为 float64类型

对于json中的数组 会解析结构体字段类型为  []interface{}类型

对于json中的对象 会解析结构体字段类型为   map[string]interface{}类型

对于json中的null 会解析结构体字段类型为  nil类型

例如下面这个:

type Response struct {
    Code float64     `json:"code"`
    Msg  string      `json:msg`
    Data map[string]interface{} `json:data`
}

 

猜你在找的Go相关文章