如何将此 JSON 字符串转换为结构?

盖伊

如何将此 JSON 字符串转换为两个不同的数组?我想要一个bids 数组和一个asks 数组,但是,我不确定。这是 JSON:

{

   "lastUpdateId":6219028865,
   "bids":[
         "45529.93000000",
         "0.59554000"
      ],
      [
         "45529.92000000",
         "0.04402000"
      ],
   ],
   "asks":[
      [
         "45529.94000000",
         "3.77220000"
      ],
      [
         "45529.95000000",
         "0.07800000"
      ],
   ]
}

我从请求中收到 JSON:

b, err := ioutil.ReadAll(resp.Body)

我将如何进行这个过程?

姆科普里瓦
type Output struct {
    LastUpdateId int64
    Bids         [][]string
    Asks         [][]string
}

// ...

var out Output
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
    panic(err)
}

fmt.Println(out.Bids)
fmt.Println(out.Asks)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章