golang中的unmarshal数组json

时间:2017-05-11 12:21:04

标签: json go

我如何解组这样的东西:

[
2,
"19223201",
"SomeString",
{
    "SomeField": "FieldValue",
    "SomeField2": "FieldValue2", "SomeFieldN": "FieldValueN",       }
]

1 个答案:

答案 0 :(得分:0)

如果您没有定义任何接口并在接口类型切片中解组,则可以使用interface{}

import (
    "fmt"
    "encoding/json"
)

func main() {

    strBytes := []byte(`[2,"19223201", "SomeString",{"SomeField": "FieldValue","SomeField2": "FieldValue2", "SomeFieldN": "FieldValueN"}]`)
    keys := make([]interface{},0)

    json.Unmarshal(strBytes, &keys)
    fmt.Println(keys)

}