Created
April 7, 2017 04:52
-
-
Save k82cn/5081f64d160dc166e29dc2d0ac4e057b to your computer and use it in GitHub Desktop.
An example of json in golang.
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
func main() { | |
var jsonBlob = []byte(`[ | |
{"Name": "Platypus", "Order": "Monotremata"}, | |
{"Name": "Quoll", "Order": "Dasyuromorphia"} | |
]`) | |
type Animal struct { | |
Name string `json:"name"` | |
Order string `json:"order"` | |
} | |
var animals []Animal | |
json.Unmarshal(jsonBlob, &animals) | |
fmt.Printf("%+v\n", animals) | |
str, _ := json.Marshal(animals[0]) | |
fmt.Printf("%+v\n", string(str)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment