1. 程式人生 > >golang的json數據解析

golang的json數據解析

str new json port imp github data this req

import (
    "fmt"
    "time"

    "github.com/astaxie/beego"
    "github.com/bitly/go-simplejson"
)
type Datas struct {
        data struct {
            Id     int64     `json:"id"`
            Userid string    `json:"userid"`
            Title  string    `json:"title"`
            Txt    string    `json:"txt"`
            Date   time.Time `json:"date"`
        } `json:"data"`
    }

json, _ := simplejson.NewJson(this.Ctx.Input.RequestBody)
    datas, _ := json.Get("data").Array()

    for _, v := range datas {
        fmt.Println(v)
        temp, _ := v.(map[string]interface{})
        fmt.Println(temp["id"])
    }

golang的json數據解析