Runtime error: assignment to entry in nil map

前端 未结 4 1099
逝去的感伤
逝去的感伤 2021-01-31 12:53

I am trying to generate a map and then convert that to a yaml file like this:

uid :
      kasi:
        cn: Chaithra
        street: fkmp
      nandan:
        c         


        
4条回答
  •  旧巷少年郎
    2021-01-31 13:52

    You should check if the map is nil and initialize one if it's nil inside the for loop:

    if m["uid"] == nil {
        m["uid"] = map[string]T{}
    }
    

提交回复
热议问题