[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-FLY,一套可私有化部署的免费开源客服系统,安装过程不超过五分钟(超过你打我 !),基于Golang开发,二进制文件可直接使用无需搭开发环境,下载zip解压即可,仅依赖MySQL数据库,是一个开箱即用的网页在线客服系统,致力于帮助广大开发者/中小站长快速整合私有客服功能
github地址:go-fly
官网地址:https://gofly.sopans.com

赞赏作者

微信交流

原文地址:https://www.cnblogs.com/taoshihan/p/14389752.html