<分区>
假设我有这个数据:
{
"code": 10000,
"msg": "Successful request processing",
"asks": [
[
"0.03434400",
"0.31100000"
],
[
"0.03436300",
"0.18900000"
],
[
],
"bids": [
[
"0.03427400",
"0.21100000"
],...
感谢 Go to JSON 转换器,我知道它可以像这样解析(在我的脚本中工作):
type AutoGenerated struct {
Code int `json:"code"`
Msg string `json:"msg"`
Asks [][]string `json:"asks"`
Bids [][]string `json:"bids"`
}
我宁愿这样解析它:
type Box struct {
Number int `json:"code"`
Message string `json:"msg"`
Asks []MarketData `json:"asks"`
Bids []MarketData `json:"bids"`
}
type MarketData struct {
Sell []string
}
或者,更好的是,这个(假设 Box 结构保持不变):
type MarketData struct {
SellPrice string
SellQuantity string
}
问题是,如果我尝试使用 price :=response.Asks[0].SellPrice 或使用前面的示例 response.Asks[0].Sell 来打印上面的内容,我会得到一个空结构。
为什么这行不通?对我来说,这似乎是合法的。它构建良好,但每当我尝试运行它时,它都会打印空括号。