type Address struct { City string`json:"city"` Street string`json:"street"` ZipCode string`json:"zip_code,omitempty"` Coordinate coordinate `json:"coordinate,omitempty"` }
type coordinate struct { Lat float64`json:"latitude"` Lng float64`json:"longitude"` }
funcTestMarshal(t *testing.T) { data := `{ "city": "Beijing", "street": "a" }` addr := &Address{} json.Unmarshal([]byte(data), addr)
type Address struct { City string`json:"city"` Street string`json:"street"` ZipCode string`json:"zip_code,omitempty"` Coordinate *coordinate `json:"coordinate,omitempty"` }
type coordinate struct { Lat float64`json:"latitude"` Lng float64`json:"longitude"` } // ... 同上 忽略 /* { "city": "Beijing", "street": "a" } */
type coordinate struct { Lat float64`json:"latitude,omitempty"` Lng float64`json:"longitude,omitempty"` }
funcTestMarshal(t *testing.T) { data := `{ "latitude": 1.0, "longitude": 0.0 }` c := &coordinate{} json.Unmarshal([]byte(data), c) fmt.Printf("%#v\n", c)