I am working in Golang,and using the package github.com/bitly/go-simplejson
I will receive a Json from the client side, I already constructed the json object using that package. Now I need to iterate over all the "first level" elements of that Json. The Json is something like this:
{"Name":"demo2","Creator":"some creator","URL":"www.url.com","GACode":"UA-xxxx"}
My code is:
body, _ := ioutil.ReadAll(req.Body)
settings,_ := simplejson.NewJson(body)
fmt.Printf("
Json: %+v",settings)
for k, v := range settings.MustArray() {
fmt.Println("
k:",k)
fmt.Println("
v:",v)
}
When I print the Json I receive:
Json: &{data:map[Name:demo2 Creator:some creator URL:www.url.com GACode:UA-xxxx]}
And the loop is giving me nothing, MustArray() is giving me an empty array. The keys of that Json are very dynamic so I cannot do somehting like .Get("TheKey")
because I don't know the name of the keys that can come in the json.
Then, how can I loop over that Json? I am more insterested in loop over the first level of that Json.