Unmarshaling json into a type

后端 未结 2 1426
没有蜡笔的小新
没有蜡笔的小新 2021-01-27 21:19

I get the following data:

{
  \"timestamp\": \"1526058949\",
  \"bids\": [
    [
      \"7215.90\",
      \"2.31930000\"
    ],
    [
      \"7215.77\",
      \"         


        
2条回答
  •  生来不讨喜
    2021-01-27 21:35

    You are treating your bids as a structure of two separate strings, when they are really a slice of strings in the JSON. If you change OrderBookItem to be

    type OrderBookItem []string
    

    which is how you have defined them in the second bit, which works.

    To access the values you just have to do: price := d.Bids[0] amount := d.Bids[1]

提交回复
热议问题