doumen5087 2018-01-21 20:09
浏览 52
已采纳

http:紧急服务[:: 1]:57685:分配给零图中的条目

I am trying to make a vcard using golang.My code is:

    var (
    // card is a map of strings to []*vcard.Field objects
    card vcard.Card

    // destination where the vcard will be encoded to
    enc = vcard.NewEncoder(destFile) 
)
var str []string


for i, entry := range k {


    if i!=2{
        str=append(str,k[i])


        card.SetValue(vcard.FieldFormattedName, strings.Join(str[:i],""))//panic occurs here
        fmt.Println(str)

    }else if i==2{
        card.SetValue(vcard.FieldTelephone, entry)
    }else{
        card.SetValue(vcard.FieldOrganization, entry)
    }




    // set the value of a field and other parameters by using card.Set
    card.Set(vcard.FieldName, &vcard.Field{
        Value: strings.Join(str[:2], ";"),
        Params: map[string][]string{
            vcard.ParamSortAs: []string{
                k[0] + " " + k[1],
            },
        },
    })

The json document which has to be stored in vcf is:

      {"firstname":"Vilas","lastname":"Prakash","mobile":"8732647482","organisation":"Dbjb"}

I have marshalled the json to []string.On executing I am getting the following error:

    http: panic serving [::1]:57685: assignment to entry in nil map

Can anyone help me???Or Is there any other way of creating .vcf or vcard in golang using json document as input???

  • 写回答

1条回答 默认 最新

  • dst8922 2018-01-21 21:32
    关注

    You haven't initialized your map. I suggest you read up on how maps work in Go https://blog.golang.org/go-maps-in-action

    In the meantime

    var card vcard.Card
    

    should be

    var card = make(vcard.Card)
    

    I'm not familiar with the vcard data structure. But you mention that it should be a map -> string][]*vcard.Field.. If the above make fails change it to

    var card = make(map[string][]*vcard.Field)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加