我希望有一张格式如下的地图:
mapName[someIntegerID].Title.EN_US
mapName[someIntegerID].Title.ZH_HK
mapName[someIntegerID].Title.ZH_CN
mapName[someIntegerID].Content.EN_US
mapName[someIntegerID].Content.ZH_HK
mapName[someIntegerID].Content.ZH_CN
其实上面说的有道理吗?无论如何,我尝试了下面的代码。api json 响应格式是完美的,但是,我注意到在 forloop 期间,zh_HK 将覆盖 en_US 的,以及 zh_CN 将覆盖 zh_HK 和 en_US,导致正确的 zh_CN 值但空 en_US 和 zh_HK 值。
专家可以给我一些建议,我该如何实现它?
type Hello struct {
Title Locale `json:"title"`
Content Locale `json:"content"`
}
type Locale struct {
EN_US string `json:"en-US"`
ZH_HK string `json:"zh-HK"`
ZH_CN string `json:"zh-CN"`
}
someMap := map[int]Hello{}
for _, recordTranslations := range recordsTranslations {
if _, has := someMap[recordTranslations.SchoolGroupID]; !has {
someMap[recordTranslations.SchoolGroupID] = Hello{}
}
if recordTranslations.Locale == "en-US" {
someMap[recordTranslations.SchoolGroupID] = Hello{
Title: Locale{
EN_US: recordTranslations.Title,
},
Content: Locale{
EN_US: recordTranslations.Content,
},
}
} else if recordTranslations.Locale == "zh-HK" {
someMap[recordTranslations.SchoolGroupID] = Hello{
Title: Locale{
ZH_HK: recordTranslations.Title,
},
Content: Locale{
ZH_HK: recordTranslations.Content,
},
}
} else if recordTranslations.Locale == "zh-CN" {
someMap[recordTranslations.SchoolGroupID] = Hello{
Title: Locale{
ZH_CN: recordTranslations.Title,
},
Content: Locale{
ZH_CN: recordTranslations.Content,
},
}
}
}
慕工程0101907
相关分类