[英]How do I parse a HTTP Response of following format
I am using the bulk sms api to trigger send an sms to mobile number in and android phone. 我正在使用批量短信API触发发送短信到Android手机中的手机号码。 The format of the bulk sms api is follows
批量短信API的格式如下
http://xxx.xxx.xxx/bulksms/bulksms?username=fds-xxx&password=xxx&type=0&dlr=1&destination=9422522891,8275004333&source=xxx&message=18%20December
The following is the response I can get in android as string using code 以下是我可以使用代码作为字符串在android中获得的响应
bytesSent = httpclient.execute(httppost, res);
response below 回应如下
1701|919422522891:224c1214-bb95-414d-ba76-77db95370545,1701|918275004333:5e93a439-2644-4455-9f01-f27e6cf0cde6
How do I parse this response like key value pairs ? 如何像键值对那样解析此响应?
A little success with following code , but it fails when the regex char is '|' 以下代码取得了一些成功,但是当正则表达式char为'|'时失败了
public String[] split(String regex,String input)
{
input = "1701|919422522891:224c1214-bb95-414d-ba76-77db95370545,1701|918275004333:5e93a439-2644-4455-9f01-f27e6cf0cde6";
regex = "|"; // does not work
//regex = ":"; // works correct
String[] soso = Pattern.compile(regex).split(input, input.length());
for (String s : soso) {
Log.e("TAG",s.toString());
}
return null;
}
for regex char '|' 用于正则表达式字符“ |”
I get a Log output as single characters string array like {"1","7","0",........} 我得到一个Log输出为单个字符串数组,例如{“ 1”,“ 7”,“ 0”,........}
UPDATE UPDATE
regex = "\\|" // works fine
result[0]
is the key, result[1]
is the value result[0]
是键, result[1]
是值 if you need to maintain order make sure you use a map that does that, eg LinkedHashMap 如果您需要保持秩序,请确保使用能做到这一点的地图,例如LinkedHashMap
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.