简体   繁体   English

Android无法使用ez-vcard从VCARD获取正确的街道地址

[英]Android not getting proper street address from VCARD using ez-vcard

I'm using ez-vcard ( https://github.com/mangstadt/ez-vcard ) for parsing VCARD string. 我正在使用ez-vcard( https://github.com/mangstadt/ez-vcard )解析VCARD字符串。 For example one of VCARD string is 例如,VCARD字符串之一是

"BEGIN:VCARD\n" +
"N:Mandal;Saroj\n" +
"FN:Saroj Mandal\n" +
"ORG:xyz\n" +
"TITLE:Advisory Software Engineer\n" +
"TEL;WORK:022-123456\n" +
"TEL;CELL:1234567890\n" +
"TEL;FAX:1234567890\n" +
"ADR;ADDRESS:;;D-100, Tech Heights, Sainikwadi, Wadgaonshri;Pune;Maharashtra;411014;India\n" +
"LABEL;ADDRESS;ENCODING=QUOTED-PRINTABLE:D-100,Tech Heights, Sainikwadi, Wadgaonshri=0D=0Pune, Maharashtra=0D=0411014=0D=0India\n" +
"EMAIL;PREF;INTERNET:hificoders@gmail.com\n" +
"URL;WORK:http://www.example.com\n" +
"END:VCARD";

In android I want street address from above example VCARD string I have used below code 在android中,我想要上面示例VCARD字符串中的街道地址

for(Address address :vcard.getAddresses()){
   Log.d(TAG, "Street address" + address.getStreetAddress());
}

But i'm getting only D-100 as street address , it should be D-100, Tech Heights, Sainikwadi, Wadgaonshri, but If I remove comma(,) from above VCARD then Im getting whole string. 但是我只有D-100作为街道地址,应该是D-100,Tech Heights,Sainikwadi,Wadgaonshri,但是如果我从VCARD上方删除逗号(,),那么我会得到整个字符串。 Please give some solution. 请提供一些解决方案。

Comma characters must be escaped in the ADR property. 逗号字符必须在ADR属性中转义。 Put backslashes before all the commas. 在所有逗号前加反斜杠。

"ADR;ADDRESS:;;D-100\, Tech Heights\, Sainikwadi\, Wadgaonshri;Pune;Maharashtra;411014;India\n" +

Also, why the heck to do you have a value-less "ADDRESS" parameter in your property?? 另外,为什么要在属性中添加一个无值的“ ADDRESS”参数呢? Remove that, please. 请删除它。

"ADR:;;D-100\, Tech Heights\, Sainikwadi\, Wadgaonshri;Pune;Maharashtra;411014;India\n" +

EDIT (Jul 27 2015): 编辑(2015年7月27日):

To answer the question in your comment: 要回答您评论中的问题:

To force the parser to treat commas as normal characters, you can register a custom scribe class which extends the standard AddressScribe scribe and overrides its parsing function: 要强制解析器将逗号视为普通字符,您可以注册一个自定义书写器类,该类扩展了标准的AddressScribe并覆盖了其解析功能:

VCardReader reader = new VCardReader(...);
reader.getScribeIndex().register(new AddressScribe() {
    @Override
    protected Address _parseText(String value, VCardDataType dataType, VCardVersion version, VCardParameters parameters, List<String> warnings) {
        String components[] = value.split(";");
        int i = 0;

        Address property = new Address();
        property.setPoBox(next(components, i++));
        property.setExtendedAddress(next(components, i++));
        property.setStreetAddress(next(components, i++));
        property.setLocality(next(components, i++));
        property.setRegion(next(components, i++));
        property.setPostalCode(next(components, i++));
        property.setCountry(next(components, i++));
        return property;
    }

    private String next(String components[], int index) {
        if (index >= components.length) {
            return null;
        }
        String next = components[index];
        return (next.length() > 0) ? next : null;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM