I have not run this. But based on your comments, jsonvals is a slice. So 
you would presumably need to check the length then access a specific item 
in the slice like this: fmt.Printf("\n%+v\n", jsonvals[0].ID)

Hope that helps.



On Monday, March 12, 2018 at 12:01:33 PM UTC-4, asyncp...@gmail.com wrote:
>
> Go Noob here, confused about struct. My result is type []gjson.Result but 
> I can't extract a named value from this struct. Help greatly appreciated, I 
> have tried several articles.
>
> package main
>
> import (
>    "fmt"
>    "github.com/tidwall/gjson"
>    "reflect"
> )
>
>
> func main() {
>    // JSON package gjson
>    const json = `{"pass":true,"balance":180,"who":"f","ID":4231}]`
>
>    jsonvals := gjson.GetMany(string(json), "pass", "balance", "ID")
>    fmt.Printf("%+v\n", jsonvals)  // result: [true 180 4231]
>    fmt.Println(reflect.TypeOf(jsonvals)) // result: []gjson.Result
>    fmt.Printf("\n%+v\n", jsonvals.ID) // fails here, why? it is a struct, 
> right???
>
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to