1. 程式人生 > >go json 反序列化

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)) }