-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is the key 0 #361
Comments
The For example: package main
import (
"fmt"
"github.com/tidwall/gjson"
)
func main() {
str := `[
{"drawNumber": "51117487"},
{"drawNumber": "51117486"},
{"drawNumber": "51117485"},
{"drawNumber": "51117484"},
{"drawNumber": "51117483"},
{"drawNumber": "51117482"}
]`
gjson.Parse(str).ForEach(func(key, value gjson.Result) bool {
fmt.Println("key", key.Int())
fmt.Println("key", value.Get("drawNumber").Int())
return true
})
}
|
Very strange, I copied your code snippet for testing, but the result is still 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
func TestParseJSON(t *testing.T) { str :=
[{"drawNumber":"51117487"},
{"drawNumber":"51117486"},
{"drawNumber":"51117485"},
{"drawNumber":"51117484"},
{"drawNumber":"51117483"},
{"drawNumber":"51117482"},
{"drawNumber":"51117481"},
{"drawNumber":"51117480"},
{"drawNumber":"51117479"},
{"drawNumber":"51117478"},
{"drawNumber":"51117477"},
{"drawNumber":"51117476"},
{"drawNumber":"51117475"},
{"drawNumber":"51117474"},
{"drawNumber":"51117473"},
{"drawNumber":"51117472"},
{"drawNumber":"51117471"},
{"drawNumber":"51117470"}
]
gjson.Parse(str).ForEach(func(key, value gjson.Result) bool { fmt.Println("key", key.Int()) fmt.Println("key", value.Get("drawNumber").Int()) return true }) }
The text was updated successfully, but these errors were encountered: