A json stream described an array of shapes. The shapes mayb be triangles, rectangles or squares.
For example:
{"shapes": [
{"type": "triangle", "side1": 3, "side2": 4, "side3": 5},
{"type": "rectangle", "width": 4, "height": 3},
{"type": "square", "side": 3}
]}
These structures are declared in my golang code:
type Shape struct {
Type string `json:"type"`
}
type Triangle struct {
Shape
Side1 int `json:"side1"`
Side2 int `json:"side2"`
Side3 int `json:"side3"`
}
type Rectangle struct {
Shape
Width int `json:"width"`
Height int `json:"height"`
}
type Square struct {
Shape
Side int `json:"side"`
}
How can I decode the json into an object slice? Thank you very much.