无法从 soap 响应中获取值
Not able to get the values from soap response
这是我的代码
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("MobileNbr","9959077764");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
androidHttpTransport.debug = true;
SoapObject response = (SoapObject)envelope.bodyIn;
System.out.println(response);
String result = response.getProperty(0);
System.out.println(result);
}catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
这是我得到的回复。
GetCabListResponse{GetCabListResult=<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>; }
这是从 response.getProperty(0);
得到的结果
<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>
我想要 status 和 cab 的值
这是从返回的 XML 中提取数据的正则表达式解决方案:
String cab ="<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>";
Pattern p = Pattern.compile("<status>([^<]+)</status><cab>([^<]+)</cab>");
Matcher m = p.matcher(cab);
if(m.find()) {
System.out.println("Status: " + m.group(1));
System.out.println("Cab: " + m.group(2));
}
多辆出租车:
String cab ="<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>";
Pattern p = Pattern.compile("<status>([^<]+)</status>((<cab>([^<]+)</cab>)*)");
Matcher m = p.matcher(cab);
if(m.find()) {
System.out.println("Status: " + m.group(1));
List<String> cablist = Arrays.asList(m.group(2).replace("<cab>", "").replace("</cab>", "#").split("#"));
System.out.println("Cab: " + cablist);
}
这是我的代码
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("MobileNbr","9959077764");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
androidHttpTransport.debug = true;
SoapObject response = (SoapObject)envelope.bodyIn;
System.out.println(response);
String result = response.getProperty(0);
System.out.println(result);
}catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
这是我得到的回复。
GetCabListResponse{GetCabListResult=<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>; }
这是从 response.getProperty(0);
得到的结果<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>
我想要 status 和 cab 的值
这是从返回的 XML 中提取数据的正则表达式解决方案:
String cab ="<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>";
Pattern p = Pattern.compile("<status>([^<]+)</status><cab>([^<]+)</cab>");
Matcher m = p.matcher(cab);
if(m.find()) {
System.out.println("Status: " + m.group(1));
System.out.println("Cab: " + m.group(2));
}
多辆出租车:
String cab ="<CabList><status>0</status><cab>AP09BS9127</cab><cab>AP09BS9126</cab></CabList>";
Pattern p = Pattern.compile("<status>([^<]+)</status>((<cab>([^<]+)</cab>)*)");
Matcher m = p.matcher(cab);
if(m.find()) {
System.out.println("Status: " + m.group(1));
List<String> cablist = Arrays.asList(m.group(2).replace("<cab>", "").replace("</cab>", "#").split("#"));
System.out.println("Cab: " + cablist);
}