douyong4842
2019-08-22 08:07
浏览 37
已采纳

无法将复合文字与map [string] [] struct一起使用[关闭]

I am trying to use composite literal with maps but unable to use it as it shows some error.

please find the code below.

I am a newbie to Golang and perhaps have some less understanding about composite literals.

type Assessment struct{
    StructuringForce map[string][]StructuringForce
}

type StructuringForce struct {
    Principles       map[string][]Capabilities
}

type Capability struct {
}

c1 := Capability{}

a1 := Assessment{

        StructuringForce : map[string][]StructuringForce{
            "Information Systems" , []StructuringForce{
                StructuringForce{
                    Principles : map[string][]Capabilities{
                        "Integration of IT Services" ,[]Capabilities{
                            c1,
                        },
                    },
                },
            },
        },


    }

while constructing "a1" with composite literals I get "Missing key in map literals error".

But i can see that i have added keys.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将复合文字与地图一起使用,但由于显示某些错误而无法使用它。</ p>

请找到下面的代码。</ p>

我是Golang的新手,可能对复合文字的理解较少。</ p>

 <代码>类型评估结构{
 StructuringForce map [string] [] StructuringForce 
} 
 
type StructuringForce struct {
 Principles map [string] [] Capabilities 
  } 
 
type Capability struct {
} 
 
c1:= Capability {} 
 
a1:= Assessment {
 
 StructuringForce:map [string] [] StructuringForce {
“ Information Systems”,[  ] StructuringForce {
 StructuringForce {
原理:map [string] []功能{
“ IT服务的集成”,[]功能{
 c1,
},
},
},
  },
},
 
 \  n} 
 </ code> </ pre> 
 
 

同时使用复合文字构造“ a1”时,我得到“地图文字错误中缺少键”。</ p>

但是 我可以看到我已经添加了键。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题