我正在尝试为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文件
开始:VCARD版本:3.0N: Gump;Forrest;;FN:Forrest Gump ORG:Bubba Gump虾公司标题:虾人TEL;TYPE=HOME,语音:(111) 555-1212 PHOTO;VALUE=URL;TYPE=GIF:photo.gif TEL;TYPE=WORK,语音:(111) 555-12121 ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;美利坚合众国LABEL;TYPE=WORK:100 Waters边缘\n Baytown,LA 30314\n美利坚合众国ADR;TYPE=HOME:;;42种植园St..;Baytown;LA;30314;美利坚合众国标签;TYPE=HOME:42种植园St.nBaytown,LA 30314\n美利坚合众国EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com REV:2008-04-24T19:52:43Z结束:VCARD开始:VCARD版本:3.0 N: Gump;Forrest;FN:Forrest Gump ORG:Bubba Gump虾公司标题:虾人TEL;TYPE=HOME,声音:(111) 555-1212 PHOTO;VALUE=URL;TYPE=GIF:photo.gif TEL;TYPE=WORK,声音:(111) 555-12121 ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;美利坚合众国LABEL;TYPE=WORK:100 Waters Edge\n Baytown,LA 30314\n美利坚合众国ADR;TYPE=HOME:;;42种植园St..;Baytown;LA;30314;美利坚合众国LABEL;TYPE=HOME:42种植园St..\n Baytown,LA 30314\n美利坚合众国EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com REV:2008-04-24T19:52:43Z END:VCARD
logcat输出:它只适用于sample.vcf中的一个vcard数据,但是当它包含更多数据时,它会出现错误,即无效的vCard数据:缺少一个或多个必需元素(版本和FN)。
发布于 2014-07-18 08:07:00
我想这里有几个问题:
请看一下vcardparser库。
var vcardparser = require('vcardparser');
vcardparser.parseFile("./sample.vcf", function(err, json) {
if(err)
return console.log(err);
console.log(json);
});这是一个示例vcard:
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' }https://stackoverflow.com/questions/24817820
复制相似问题