Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32690
  • 博文数量: 9
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-18 18:25
个人简介

编程学习

文章分类

全部博文(9)

分类: 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)

}
                                   
阅读(2105) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~