1 回答
![?](http://img1.sycdn.imooc.com/5333a0490001f9ff02200220-100-100.jpg)
TA贡献1946条经验 获得超3个赞
为了解决这类问题,我们可以使用interface{}
这里如何使用它:
package main
import (
"encoding/json"
"fmt"
"reflect"
)
func main() {
XJson := `
{
"a": [
[
"aaa",
15
],
[
"bbb",
11
]
]
}`
var Output StructJson
json.Unmarshal([]byte(XJson), &Output)
fmt.Println("Output:", Output)
// Prints: aaa string
fmt.Println("Data on path Output.A[0][0]:", Output.A[0][0], reflect.TypeOf(Output.A[0][0]))
// Prints: 15 float64
fmt.Println("Data on path Output.A[0][1]:", Output.A[0][1], reflect.TypeOf(Output.A[0][1]))
}
type StructJson struct {
A [][]interface{} `json:"a"`
}
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报