Created
June 16, 2020 19:56
-
-
Save PriitParmakson/4bc2dab778b05529b607737b513064c8 to your computer and use it in GitHub Desktop.
Reading top level JSON array
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
// Lõik loetakse failist. | |
type Lõik struct { | |
Algus punktinimi `json:"a"` | |
Lõpp punktinimi `json:"l"` | |
Pikkus float32 `json:"p"` | |
} | |
var lõigud []Lõik | |
func loeLõigud() { | |
data, err := ioutil.ReadFile("data.json") | |
if err != nil { | |
panic(err) | |
} | |
lõigud = make([]Lõik, 0) | |
json.Unmarshal(data, &lõigud) | |
fmt.Printf("Loetud %v lõiku.\n", len(lõigud)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment