服务器返回的是一个字符串【实质是一个二维数组,在一个标签里面】
1.给服务法的请求和返回格式
>>>>>>>>>>>>>>>>>>>>>>>>>>>request:<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<sky:getPaymentInfo xmlns:sky='http://longcdcn.gicp.net:7890/stsf/services/IPHONEGZIPTICKETSERVICE'>
<terminalId>358148045004426;Tandroid02_120810:72229B8C861CE780F253BE3B86FC631D</terminalId>
<phonePackets>resultStatus={4000};memo={};result={partner="2088701258484254"&seller="2088701258484254"&out_trade_no="4598"&subject="机票"&body="航空机票信息"&total_fee="0.01"&notify_url="http://122.200.66.107:7772/stsf/RSANotifyReceiver"&success="false"&sign_type="RSA"&sign="CsH0dfGqamiZP3RP/bTSeeDWT+UjxBfYE3PIqobHOQ4LRy1uqZIVPy4PHiXDRtqcueksFe71v9lGlcS7Xh0cTZW0mNjY20EIG93sI/qewJPe1WvbhhAFTm4lZK4kNHokPEZRysJXntcw+LQm0Oci1WvROh/RVChDoaFToo2qz8w="}</phonePackets>
<paymentChannels>00</paymentChannels>
<times>1</times>
<orderID>4598</orderID>
<userID>12228</userID>
</sky:getPaymentInfo>
</soap:Body>
</soap:Envelope>
>>>>>>>>>>>>>>>>>>>>>>>>>>>response:<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:getPaymentInfoResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://longcdcn.gicp.net:7890/stsf/services/IPHONEGZIPTICKETSERVICE"><getPaymentInfoReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">[["02","支付失败"]]</getPaymentInfoReturn></ns1:getPaymentInfoResponse></soapenv:Body></soapenv:Envelope>
2.对服务器返回的二维数组的解析【解析完后封装到bean中】
// 二维解析response方法
public static TicketPayInfo analyticalPaymentInfo(String response,String value) throws IOException {
if (response == null)
return null;
List<TicketPsgInfo> list;
try {
InputStream is = new ByteArrayInputStream(response.getBytes());
String target = getJSONStringFromXml(is, value);
// JSON数据格式:
// [["0","","1234"],["张三","0","610326195612355","6356"],["张三","0","610326195612355","6356"]]
JSONArray jsonArray = new JSONArray(target);
String resultInfo = jsonArray.getString(0);
JSONArray resultInfoJsonArray = new JSONArray(resultInfo);
String resultCode = resultInfoJsonArray.getString(0);
TicketPayInfo tinfo = new TicketPayInfo();
tinfo.setResultNo(resultCode);
tinfo.setReturnErrorDescription(resultInfoJsonArray.getString(1));
if(resultCode.equals("0")){
tinfo.setOrderId(resultInfoJsonArray.getString(2));
if (jsonArray.length() > 1) {// 有旅客信息的时候
list = new ArrayList<TicketPsgInfo>();
for (int i = 1; i < jsonArray.length(); i++) {
String elementStr = jsonArray.getString(i);
JSONArray elementJSONArray = new JSONArray(elementStr);
TicketPsgInfo psgInfo = new TicketPsgInfo();
psgInfo.setPsgName(elementJSONArray.getString(0));
psgInfo.setPsgType(elementJSONArray.getString(1));
psgInfo.setIDNo(elementJSONArray.getString(2));
psgInfo.setTicketNoList(elementJSONArray.getString(3));
list.add(psgInfo);
}
tinfo.setList(list);
}
}
is.close();
return tinfo;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
3.封装到一个bean中:
bean的格式
public class TicketPayInfo implements Serializable{
private static final long serialVersionUID = -2654168829469680785L;
private String ResultNo;// 返回的状态码
private String orderId;// 隆畅达交易订单号
private String returnErrorDescription;// 对错误/异常的详细描述信息
private List<TicketPsgInfo> list;
}
public class TicketPsgInfo implements Serializable{
private static final long serialVersionUID = 431854219338230136L;
private String PsgName; // 旅客姓名,全中文;英文或拼音时,姓和名用”/”分隔;不用包含空格
private String PsgType;// 旅客类型(0-成人;1-儿童;)
private String IDNo;// 旅客证件号码;不能包含中文
private String TicketNoList;// 机票票号
}