go json 反序列化

code

解析该段json

{
    "e":"ohlcv24",
    "data":[
        "7469.6",
        "7541.1",
        "7156",
        "7213.4",
        64856543672
    ],
    "pair":"BTC:USD"
}

go 代码

type JExchange struct {
    E    string        `json:"e,omitempty"`
    Data []interface{} `json:"data,omitempty"`
    Pair string        `json:"pair,omitempty"`
}

func main() {

    var strByte = []byte(`{"e":"ohlcv24","data":["7469.6","7541.1","7156","7213.4",64856543672],"pair":"BTC:USD"}`)

    var Unpack = JExchange{}
    err := json.Unmarshal(strByte, &Unpack)

    if err != nil {
        fmt.Println(err.Error())
    }

    fmt.Println(Unpack.Data[4].(float64))
}

你可能感兴趣的:(Golang,Golang学习笔记)