我正在尝试解组一个简单的jason字符串:
type City struct {
ID int `jsonapi:"primary,cities"`
CountryCode string `jsonapi:"attr,countryCode"`
Name string `jsonapi:"attr,name"`
}
func TestGetCityByID(t *testing.T) {
const mockCity = `{
"data":{
"type":"cities",
"id":"123",
"attributes":{
"name":"Berlin",
"countryCode":"DE"
}
}
}`
city := new(City)
err := jsonapi.UnmarshalPayload(strings.NewReader(mockCity), &city)
log.Info(err) //data is not a jsonapi representation of '**neustargeodata.City'
log.Info(city)
}
我无法区分json字符串和封送城市对象的结果之间的任何区别,是否知道我在做什么错?提前非常感谢!
答案 0 :(得分:1)
好吧,我只需要将&city变成城市!