Assume I have this data:
{
"code": 10000,
"msg": "Successful request processing",
"asks": [
[
"0.03434400",
"0.31100000"
],
[
"0.03436300",
"0.18900000"
],
[
],
"bids": [
[
"0.03427400",
"0.21100000"
],...
Thanks to the Go to JSON converter, I know it can be parsed like this (working, in my script):
type AutoGenerated struct {
Code int `json:"code"`
Msg string `json:"msg"`
Asks [][]string `json:"asks"`
Bids [][]string `json:"bids"`
}
I'd rather parse it like this:
type Box struct {
Number int `json:"code"`
Message string `json:"msg"`
Asks []MarketData `json:"asks"`
Bids []MarketData `json:"bids"`
}
type MarketData struct {
Sell []string
}
Or, even better, this (assuming Box struct stays the same):
type MarketData struct {
SellPrice string
SellQuantity string
}
The problem is that if I try to print the above using price :=response.Asks[0].SellPrice, or using the previous example, response.Asks[0].Sell, I get an empty struct.
Why doesn't this work? It seems like legitimate go, to me. It builds fine, but whenever I try to run it, it prints empty braces.