go - Traversing nested JSON structs -
i want traverse nested json struct , each key , value interface{}
http://play.golang.org/p/b-b3pejgjw
so want following struct
{ "tg": { "a": { "e": 100, "h": 14 }, "b": { "d": 1 }, "c": { "d": 1, "e": 1 }, "d": { "f": 1, "g": 1, "h": 1 }, "e": { "g": 1 } } }
i able following
a := js.get("tg").get("d").get("f") fmt.println(*a) // {1}
but having trouble type assert integer.
invalid type assertion: (*a).(int)
how would traverse whole struct , each integer mapped characters?
thanks!
your value marshalled float64
. plus not accessing a.data
a
instead struct causing error.
fmt.printf("%#v\n", a) // &main.json{data:1} fmt.println(reflect.typeof(a.data)) // float64 x := int(a.data.(float64))
Comments
Post a Comment