-
-
Save alextanhongpin/12ca8509a51e9d11b26460aa2daa0b2c to your computer and use it in GitHub Desktop.
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" | |
"io/ioutil" | |
"log" | |
) | |
func loadJSON(file string, obj interface{}) error { | |
body, err := ioutil.ReadFile(file) | |
if err != nil { | |
return err | |
} | |
return json.Unmarshal(body, &obj) | |
} | |
// Point represents the schema of the json we want to load | |
type Point struct { | |
X int `json:"x"` | |
Y int `json:"y"` | |
} | |
func main() { | |
var points []Point | |
if err := loadJSON("out.json", &points); err != nil { | |
log.Printf("error loading json: %v", err) | |
} | |
log.Printf("load json: %#v\n", points) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment