zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

2023-02-18 15:37:05 时间

按照文档要求

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"`
}