Created
November 10, 2013 17:08
-
-
Save meddulla/7400923 to your computer and use it in GitHub Desktop.
iterate over a go-simplejson map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
simplejson "github.com/bitly/go-simplejson" | |
"log" | |
) | |
func testMapIter () { | |
js, _ := simplejson.NewJson([]byte(`{ | |
"test": { | |
"string_array": ["asdf", "ghjk", "zxcv"], | |
"omap": {"asdf": {"subkey": 1}, "ghjk": {"subkey": 2}, "zxcv":{"subkey": 3}}, | |
"array": [1, "2", 3], | |
"arraywithsubs": [{"subkeyone": 1}, | |
{"subkeytwo": 2, "subkeythree": 3}], | |
"int": 10, | |
"float": 5.150, | |
"string": "simplejson", | |
"bool": true | |
} | |
}`)) | |
amap := js.Get("test").Get("omap") | |
for k, v := range amap.MustMap() { | |
ndata, _ := v.(map[string]interface{}) | |
val, _ := ndata["subkey"] | |
log.Printf("%s key, %s", k, val) | |
} | |
} | |
func main () { | |
testMapIter() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment