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

 

posted @ 2021-02-08 17:37  唯一客服系统开发笔记  阅读(518)  评论(0编辑  收藏  举报