【发布时间】:2021-10-08 21:48:18
【问题描述】:
我在尝试从特定请求响应映射一些数据时遇到问题,因为在 seriesLabels 内部:有数据没有属性名称 (int,string),所以我很困惑如何映射该数据:
这是服务响应:
{
"data": {
"seriesLabels": [
[
0,
"(none)"
],
[
0,
"Cerveza"
],
[
0,
"Cigarros"
],
[
0,
"Tecate"
],
[
0,
"Cafe"
],
[
0,
"Amstel"
],
[
0,
"Leche"
],
[
0,
"Ultra"
],
[
0,
"Coca cola"
],
[
0,
"Agua"
]
]
}
}
我映射该信息的结构是:
type PopularWord struct {
Data *Data `json:"data"`
}
type Data struct {
SeriesLabels []*SeriesLabels `json:"seriesLabels"`
}
type SeriesLabels struct {
value int32 `json:""`
name string `json:""`
}
我做错了什么?声明结构的正确方法是什么?
【问题讨论】:
-
你可以看看这个(非常)有用的网站mholt.github.io/json-to-go
标签: arrays json go struct unmarshalling