I have JSON that looks like this:
{
"a": [
[
"12.58861425",
10.52046452
],
[
"12.58861426",
4.1073
]
]
"b": [
[
"12.58861425",
10.52046452
],
[
"12.58861426",
4.1073
]
]
"c": "true"
"d": 1234
}
I want to unmarshall this into a struct I created:
type OrderBook struct {
A [][2]float32 `json:"a"`
B [][2]float32 `json:"b"`
C string `json:"c"`
D uint32 `json:"d"`
}
//Note this won't work because the JSON array contains a string and a float value pair rather than only floats.
Normally I would then convert this JSON into a struct in Golang as so:
orders := new(OrderBook)
err = json.Unmarshal(JSON, &orders)
Since I can't define the type struct to match the JSON this won't work. Doing a bit of reading, I think Unmarshal-ing into an interface, and then using the interface data through type checking may be a solution.
Am I going in the right direction with this?
A template showing how I might go about using the data once it's in the interface would really help.
</div>