我有以下(不完整的类型)(这是来自Docker API的响应,来自manifests端点v2模式1 https://docs.docker.com/registry/spec/manifest-v2-1/)
(说明:该段文字描述了一种数据类型,来源于Docker API,用于处理manifests端点v2模式1的请求响应。)type ManifestResponse struct {
Name string `json:"name"`
Tag string `json:"tag"`
Architecture string `json:"architecture"`
FsLayers []struct {
BlobSum string `json:"blobSum"`
} `json:"fsLayers"`
History []struct {
V1Compatibility struct {
ID string `json:"id"`
Parent string `json:"parent"`
Created string `json:"created"`
} `json:"v1Compatibility"`
} `json:"history"`
}
获取以下响应时:
{ "schemaVersion": 1,
"name": "library/redis",
"tag": "latest",
"architecture": "amd64",
"history": [
{
"v1Compatibility": "{\"id\":\"ef8a93741134ad37c834c32836aefbd455ad4aa4d1b6a6402e4186dfc1feeb88\",\"parent\":\"9c8b347e3807201285053a5413109b4235cca7d0b35e7e6b36554995cfd59820\",\"created\":\"2017-10-10T02:53:19.011435683Z\"}"
}
]
}
在使用以下代码片段进行反序列化时:
var jsonManResp ManifestResponse
if err = json.NewDecoder(res.Body).Decode(&jsonManResp); err != nil {
log.Fatal(err)
}
I get the following error:
json: cannot unmarshal string into Go struct field .v1Compatibility of type struct { ID string "json:\"id\""; Parent string "json:\"parent\""; Created string "json:\"created\"" }
完整的代码示例:https://play.golang.org/p/tHzf9GphWX 可能存在的问题是什么?