将map返回空数组而不是包含空字符串的数组。

huangapple go评论65阅读模式
英文:

Return empty array from map instead of array with empty string

问题

我有一个将ID映射到字符串数组的映射表,如下所示:accountIDs := make(map[int64][]string, 0),在我的响应中,它看起来像这样:

"AccountIDs": {
    "1": [
        "19565",
        "21423"
    ],
    "7": [
        ""
    ]
}

如何返回一个空数组而不是一个包含空字符串的数组?

英文:

I have a map of ids that map to an array of strings as such accountIDs := make(map[int64][]string, 0) and in my response this looks like:

"AccountIDs": {
    "1": [
        "19565",
        "21423"
    ],
    "7": [
        ""
    ]
}

How can I return an empty array instead of an array of empty string?

答案1

得分: 1

将值设置为[]string{}

myMap[7] = []string{}

请参见Playground

英文:

Set the value to []string{}.

myMap[7] = []string{}

See Playground

huangapple
  • 本文由 发表于 2022年4月6日 04:34:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/71758072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定