go json序列
go json序列
// test2 project main.go package main import ( "encoding/json" "fmt" // "github.com/golang/protobuf/proto" ) type DanWei struct { Unitid string Unitname string } type DanWeis struct { UnitsArr []*DanWei } func main() { var dw DanWei dw.Unitid = "1" dw.Unitname = "个" var dw2 DanWei dw2.Unitid = "2" dw2.Unitname = "双" var dws DanWeis dws.UnitsArr = append(dws.UnitsArr, &dw) dws.UnitsArr = append(dws.UnitsArr, &dw2) b, _ := json.Marshal(dws) fmt.Println(string(b)) //{"UnitsArr":[{"Unitid":"1","Unitname":"个"},{"Unitid":"2","Unitname":"双"}]} //b2, _ := proto.Marshal(&dws) //fmt.Println(string(b2)) }
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/16501407.html