【问题标题】:read & write vcard using node.js使用 node.js 读写 vcard
【发布时间】:2014-09-09 04:01:30
【问题描述】:

我正在尝试为 vcard 创建和读取两者,在 googleng 一段时间没有得到适当的示例之后,是否有任何 vcard 创建者/阅读器可以启动,

我正在尝试这个https://www.npmjs.org/package/vcard

我的代码

app.get('/',function(req,res){
    //https://github.com/Fusselwurm/vcard-js/commit/dafd17ffd226c6170849be82e9c5dae94e23b8f0
    card.readFile("./public/sample.vcf", function(err, json1) {
        if(err){  
            console.log("vcard err "+err);
            res.json(util.inspect(json1));
            }
        else
            {
            console.log("vcard json "+json1);
            console.log("vcard json "+util.inspect(json1));
            res.json(util.inspect(json1));
            }


    });
});

sample.vcf 文件

BEGIN:VCARD 版本:3.0 N:Gump;Forrest;;Mr. FN:阿甘正传组织:布巴 Gump Shrimp Co. TITLE:Shrimp Man TEL;TYPE=HOME,VOICE:(111) 555-1212 照片;价值=网址;类型=GIF:http://www.example.com/dir_photos/my_photo.gif 电话;类型=工作,语音:(111) 555-12121 ADR;类型=工作:;;100 沃特世 Edge;Baytown;LA;30314;美国 LABEL;TYPE=WORK:100 沃特斯边缘\n贝敦, LA 30314\n美利坚合众国 ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited 美国 EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com 版本:2008-04-24T19:52:43Z 结束:VCARD 开始:VCARD 版本:3.0 N:阿甘;阿甘;;先生。 FN:阿甘正传 ORG:布巴甘虾公司 TITLE:Shrimp Man TEL;TYPE=HOME,VOICE:(111) 555-1212 照片;值=URL;类型=GIF:http://www.example.com/dir_photos/my_photo.gif 电话;类型=工作,语音:(111) 555-12121 ADR;类型=工作:;;100 沃特世 Edge;Baytown;LA;30314;美国 LABEL;TYPE=WORK:100 沃特斯边缘\n贝敦, LA 30314\n美利坚合众国 ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited 美国 EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com 修订:2008-04-24T19:52:43Z 结束:VCARD

logcat 输出: 它仅适用于 sample.vcf 中的 1 个 vcard 数据,但是当它包含更多数据时,它会出现错误 IE vCard 数据无效:缺少一个或多个必需元素(VERSION 和 FN)

【问题讨论】:

    标签: javascript node.js vcf-vcard


    【解决方案1】:

    我认为这里有几个问题:

    1. 您正在使用的 vcard 库未完成
    2. 您使用的电子名片格式不正确

    改为查看 vcardparser 库。

    var vcardparser = require('vcardparser');
    
    vcardparser.parseFile("./sample.vcf", function(err, json) {
        if(err)
            return console.log(err);
        console.log(json);
    });
    

    这是一个示例电子名片:

    BEGIN:VCARD
    VERSION:4.0
    N:Gump;Forrest;;;
    FN:Forrest Gump
    ORG:Bubba Gump Shrimp Co.
    TITLE:Shrimp Man
    PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
    TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
    TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
    ADR;TYPE=work;LABEL="100 Waters Edge\nBaytown, LA 30314\nUnited States of America"
      :;;100 Waters Edge;Baytown;LA;30314;United States of America
    ADR;TYPE=home;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited States of America"
     :;;42 Plantation St.;Baytown;LA;30314;United States of America
    EMAIL:forrestgump@example.com
    REV:20080424T195243Z
    END:VCARD
    

    还有vcardparser的输出

    { begin: 'VCARD',
      version: '4.0',
      n:
       { last: 'Gump',
         first: 'Forrest',
         middle: '',
         prefix: '',
         suffix: '' },
      fn: 'Forrest Gump',
      org: { name: 'Bubba Gump Shrimp Co.', dept: undefined },
      title: 'Shrimp Man',
      photo:
       { type: [],
         value: 'http://www.example.com/dir_photos/my_photo.gif' },
      tel:
       [ { type: [Object], value: 'tel:+1-111-555-1212' },
         { type: [Object],
           value: 'tel:+1-404-555-1212ADR;TYPE=work;LABEL="100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' } ],
      '  ': ';;100 Waters Edge;Baytown;LA;30314;United States of AmericaADR;TYPE=home;LABEL="42 Plantation St.\\nBaytown, LA 30314\\nUnited States of America"',
      ' ': ';;42 Plantation St.;Baytown;LA;30314;United States of America',
      email: [ { type: [], value: 'forrestgump@example.com' } ],
      rev: '20080424T195243Z',
      end: 'VCARD' }
    

    【讨论】:

    • 我会试试这个并告诉你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 2021-03-29
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多