我试图从API调用中检索数据并将其传递给另一个服务。我收到的数据是在一个特定的JSON结构,我想把它映射到一个结构,但没有多层次的数据。我尝试了点符号来访问更深的值,但它不起作用。
基本上,我试图得到一个包含一系列“问题”(key、self、description)的结构,但没有“fields.description”结构。
JSON:
{
"ticket": {
"number": "2",
"issues": [
{
"key": "TA-2",
"self": "http://localhost:8080/rest/api/2/issue/10100",
"fields": {
"description": "This template is used to create openshift project.\n|Type|Value|Help|\n|project_name|personal_project|Enter the name of your openshift project|\n|memory|8GB|Enter the desired amount of memory|"
}
},
{
"key": "TA-1",
"self": "http://localhost:8080/rest/api/2/issue/10000",
"fields": {
"description": "This template is used to create openshift project.\n|Type|Value|Help|\n|project_name|my_openshift_project|Enter the name of your openshift project|\n|memory|4GB|Enter the desired amount of memory|"
}
}
]
}
}
结构:
type Todo struct {
Number string `json:"number"`
Issue []struct {
Key string `json:"key"`
Self string `json:"self"`
Description string `json:"field.description"` //doesn't work. don't know what to put ...
} `json:"issues"`
}
预期/期望的结构:
{
"number": "2",
"issues": [{
"key": "TA-2",
"self": "http://localhost:8080/rest/api/2/issue/10100",
"description": "This template ..."
}, {
"key": "TA-1",
"self": "http://localhost:8080/rest/api/2/issue/10000",
"description": "This template ..."
}]
}
有可能吗?如果是,怎么做?使用嵌套结构不会更改初始JSON结构。
谢啦