gpt4 book ai didi

java - 解析 ical 格式 - 解析异常

转载 作者:行者123 更新时间:2023-11-29 06:44:29 25 4
gpt4 key购买 nike

我正在使用 ical4j 来解析 Android 上的 ical 格式。

我的输入 ics 是:

    BEGIN:VCALENDAR
BEGIN:VEVENT
SEQUENCE:5
DTSTART;TZID=US/Pacific:20021028T140000
DTSTAMP:20021028T011706Z
SUMMARY:Coffee with Jason
UID:EC9439B1-FF65-11D6-9973-003065F99D04
DTEND;TZID=US/Pacific:20021028T150000
END:VEVENT
END:VCALENDAR

但是当我尝试解析它时,我得到了异常:

第 1 行错误:应为 [VCALENDAR],读取 [VCALENDARBEGIN]

相关代码为:

    HttpHelper httpHelper = new HttpHelper(
"http://10.0.2.2/getcalendar.php", params);
StringBuilder response = httpHelper.postData();

StringReader sin = new StringReader(response.toString());
CalendarBuilder builder = new CalendarBuilder();
Calendar cal = null;
try {
cal = builder.build(sin);
} catch (IOException e) {
Log.d("calendar", "io exception" + e.getLocalizedMessage());
} catch (ParserException e) {
Log.d("calendar", "parser exception" + e.getLocalizedMessage());

public class HttpHelper {
final HttpClient client;
final HttpPost post;
final List<NameValuePair> data;

public HttpHelper(String address, List<NameValuePair> data) {
client = new DefaultHttpClient();
post = new HttpPost(address);
this.data = data;
}

private class GetResponseTask extends AsyncTask<Void, Void, StringBuilder> {
protected StringBuilder doInBackground(Void... arg0) {
try {
HttpResponse response = client.execute(post);
return inputStreamToString(response.getEntity().getContent());
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return null;
}
}

public StringBuilder postData() {
try {
post.setEntity(new UrlEncodedFormEntity(data));
return (new GetResponseTask().execute()).get();
} catch (UnsupportedEncodingException e) {
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
return null;
}

private StringBuilder inputStreamToString(InputStream is)
throws IOException {
String line = "";
StringBuilder total = new StringBuilder();

// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));

// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
Log.v("debug", "Line: " + line);
}
// Return full string
return total;
}
}

最佳答案

我的猜测是响应字符串中的行结尾与 ical4j 所期望的不同。

标准指定您应该使用 CRLF(又名“\r\n”)。

关于java - 解析 ical 格式 - 解析异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com