【发布时间】:2021-12-19 13:54:32
【问题描述】:
假设我有这样的 json:
{
"a": [
[
"aaa",
15
],
[
"bbb",
11
]
]
}
我有这个代码:
func main() {
XJson := `
{
"a": [
[
"aaa",
15
],
[
"bbb",
11
]
]
}`
var Output StructJson
json.Unmarshal([]byte(XJson), &Output)
fmt.Println(Output)
}
type StructJson struct {
[][]string `json:"a"` //wrong because have 15 and 11 have int type data
///what must i do in here?
}
如何解组? 我的意思是,“aaa”和“bbb”具有数据字符串类型,15 和 11 具有数据整数类型。 如果我使用那个“错误”的结构,输出是
{[[aaa ] [bbb ]]}
【问题讨论】:
-
使用
interface{}:type StructJson struct {A [][]interface{} `json:"a"`}