golang的序列与反序列化

golang写backend之类的应用,还是挺方便的...
使用encoding/json包时, 必须注意, 在struct定义的属性必须是exported, 否则不会设置值. 例如:
type DRole struct { Id string `json:"id"`}
type DataRole struct { Roles []DRole `json:"roles"`}
type Role struct { TenantName string `json:"tenant_name"` TenantId string `json:"tenant_id"` Roles []string `json:"roles"`}
type Response struct { Ok bool `json:"ok"` Msg string `json:"msg"` UserName string `json:"user_name"` UserId string`json:"user_id"` Roles []Role `json:"roles"`}

原文地址:https://www.cnblogs.com/zolo/p/5849091.html