dprfe04886 2018-12-19 17:51
浏览 48
已采纳

如何使用golang + jason从命名的json获取数据?

I've this json:

info = {"key1": 1 , "key2": 1 , "key3": 3}

I would like to get the value from key1 with jason and NewObjectFromReader.

I'm using this code:

statusBody, err := jason.NewObjectFromReader(res.Body)
if err != nil {
    log.Fatal(err)
}

res.Body is a io.Reader, so that part is fine (I guess). go run shows this problem:

2018/12/19 18:02:40 invalid character 'i' looking for beginning of value

I think the problem is that the json starts with info= instead of {. Any idea how to parse this json?.

  • 写回答

1条回答 默认 最新

  • dotwc62080 2018-12-19 17:56
    关注

    info = is not valid JSON. Therefore, you have to start reading where the { begins and stop reading with the final closing }.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入