我使用以下代码从服务器读取内容
URL url = new URL("http://dev.dublabs.com:8080/mobileCampus/json/emergencyContacts");
HttpURLConnection httpcon = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
String inputLine;
while((inputLine=in.readLine())!=null){
System.out.println(inputLine);
}
以下是来自服务器的响应:
BEGIN:VCARD
VERSION:2.1
FN:Campus Police
N:Campus Police
TEL:555-EDU-HELP
ADR:8230 Boone Blvd.;Bldg 001;;Vienna;VA;22181;
X-MS-OL-DEFAULT-POSTAL-ADDRESS:01155
EMAIL:police@wisconsin.edu
REV:20120501T180000Z
END:VCARD
BEGIN:VCARD
VERSION:2.1
FN:Campus Medical Clinic
N:Campus Medical Clinic
TEL:555-EDU-HURT
ADR:8230 Boone Blvd.;Bldg 001;;Vienna;VA;22181;
X-MS-OL-DEFAULT-POSTAL-ADDRESS:01155
EMAIL:medical@wisconsin.edu
REV:20120501T180000Z
END:VCARD
有没有办法将其转换为JSON数组?
答案 0 :(得分:1)
好的,这是......
使用此库可以解决您的问题:https://code.google.com/p/ez-vcard/
---使用您的InputStreamReader(更准确地说:Reader)
VCard vcard = Ezvcard.parse(reader).first();
(其中reader是“Reader”类型,其中InputStreamReader是)
并使用以下代码段将其导出到JSON:
String json = Ezvcard.writeJson(vcard).go();