我无法按索引访问字段。这个库https://github.com/buger/jsonparser
来自https://github.com/buger/jsonparser的示例:
// Or use can access fields by index!
jsonparser.GetInt("person", "avatars", "[0]", "url")
我的代码:
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"))
}
导致终端: 0 未找到密钥路径