dongpu2694 2017-10-06 13:40
浏览 89

jsonparser按索引访问字段

i have problem to access fields by index. this library https://github.com/buger/jsonparser

example from https://github.com/buger/jsonparser:

// Or use can access fields by index!
jsonparser.GetInt("person", "avatars", "[0]", "url")

My code:

    package main

    import (
      "github.com/buger/jsonparser"
      "fmt"
    )
    func main () {
      data := []byte(`{
        "person": {
          "name": {
            "first": "Leonid",
            "last": "Bugaev",
            "fullName": "Leonid Bugaev"
          },
          "github": {
            "handle": "buger",
            "followers": 109
          },
          "avatars": [
            {
              "url": "https://avatars1.githubusercontent.com/u/14009?v=3&s=460",
              "type": "thumbnail"
            }
          ]
        },
        "company": {
          "name": "Acme"
        }
      }`)

      fmt.Println(jsonparser.GetInt(data, "person", "[2]", "[0]", "url"))
    }

result in terminal: 0 Key path not found

  • 写回答

1条回答 默认 最新

  • drydaenth257216154 2017-10-06 13:47
    关注

    Person is not an array so you can not access it by index.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集