编程学习
分类: Erlang
2014-11-19 08:38:16
/*
*Go语言json的级联简单使用,Created By dosthdomap In November 18 ,2014
*/
package main
import (
"encoding/json"
"fmt"
)
var jsonBlob = []byte(
`[
{ "id":123123,
"name": "golang",
"class":
{ "name": "软件工程一班",
"year":2009,
"teacher": "HanSir",
"group":
{ "name": "计算机科学与技术",
"num": 3
}
},
"classnum": 234
},
{"id":3453523523,
"name": "baihu",
"class":
{"name": "ashfsoi",
"year":2013,
"teacher": "Li",
"group":
{"name": "多媒体技术",
"num": 4
}
}, "classnum": 235
}
]`)
type AAAAA struct {
Id int64
Name string
Class struct {
Name string
Year int
Teacher string
Group struct {
Name string
Num int
}
}
Classnum int
}
func main() {
var as []AAAAA
err := json.Unmarshal(jsonBlob, &as)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v\n", as)
fmt.Println(as[0].Class.Year, as[0].Class.Group.Name)
}