我正在尝试使用 google voice api 制作一个 java 应用程序,以及一种获取 SMS 数据和 convos 的方法返回一个像这样的整个 html 页面
我编写了一个 SMSMessage 类,它将 HTML 作为字符串接收,并将解析标签之间的第一条消息数据,但它使用 arrayList 而不是 Hashmap。
package gv;
import java.util.*;
import java.util.regex.*;
public class SMSMessage {
protected String id;
protected String phoneNumber;
protected String displayNumber;
protected String message;
protected String startTime;
protected String displayStartDateTime;
protected boolean isRead;
protected String messageText;
public SMSMessage(String x){
parse(TruncateFirstMessage(x));
parseresponse(x);
}
public String TruncateFirstMessage(String xml){
int firstbracket = xml.indexOf("{");
//int secondbracket = xml.indexOf("{", firstbracket - 1);
int thirdbracket = xml.indexOf("}");
int fourthbracket = xml.indexOf("}", thirdbracket - 1);
return xml.substring(firstbracket, fourthbracket);
}
private void parseresponse(String init){
String trimmeds1 = init.substring(init.indexOf("<html><![CDATA[)"));
String trimmeds2 = init.substring(trimmeds1.indexOf(phoneNumber));
Scanner s = new Scanner(trimmeds1);
}
private void parse(String init){
Scanner s = new Scanner(init);
ArrayList<String> parsed = new ArrayList<String>();
s.useDelimiter("[},:{]");
String temp1 = "";
int count = 0;
while (s.hasNext()){
String n = s.next();
if (!n.equals("")){
count++;
String removequotes = n.replace("\"", "");
parsed.add(removequotes); }
}
id = parsed.get(3);
phoneNumber = parsed.get(5);
displayNumber = parsed.get(7);
startTime = parsed.get(9);
displayStartDateTime = parsed.get(11) + ":" + parsed.get(12);
isRead = Boolean.parseBoolean(parsed.get(21));
messageText = parsed.get(29);
}
public String toString(){
return getClass().getSimpleName() + " [ " + "id = " + id + ", phoneNumber = " + phoneNumber + ", isRead = " + isRead + ", messageText = " + messageText + ", displayStartDateTime = " + displayStartDateTime + " ]";
}
}
this will return a pretty long arrayList, like [messages, 0609dc2d10f365600fc48372fe3122a7ba3147fa, id, 0609dc2d10f365600fc48372fe3122a7ba3147fa, phoneNumber, +17654260681, displayNumber, (765) 426-0681, startTime, 1365514638712, displayStartDateTime, 4/9/13 9, 37 AM, displayStartTime, 9, 37 AM, relativeStartTime, 40 分钟前, 注意, , isRead, true, isSpam, false, isTrash, false, star, false, messageText, hi, labels, [inbox, sms, all], type, 11, children, ]
然后我得到一个特定的元素并将其分配给一个字段。
如何用键为“relativeStartTime”且值为下一个 int 的 HashMap 替换 arrayList?