Created
August 8, 2015 14:11
-
-
Save lucacervasio/9dc0f3bb64eed65aff93 to your computer and use it in GitHub Desktop.
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 characters
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"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment