Created
August 8, 2015 14:11
-
-
Save lucacervasio/9dc0f3bb64eed65aff93 to your computer and use it in GitHub Desktop.
Revisions
-
lucacervasio created this gist
Aug 8, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ package main import ( "encoding/json" "fmt" ) type mydata struct { First string `json:first` Second float32 `json:second` Third map[string]string `json:third` } func main() { b := []byte(`{ "k1" : "v1", "k3" : 10, "result":{"first": "v4","second": 12.3,"third": {"k11" : "v11", "k22" : "v22"}} }`) var objmap map[string]*json.RawMessage err := json.Unmarshal(b, &objmap) if err != nil { fmt.Println(err) } fmt.Println(objmap) var dat mydata err = json.Unmarshal(*objmap["result"], &dat) if err != nil { fmt.Println(err) } fmt.Println(dat) fmt.Println(dat.Third["k22"]) }