android中二维数组的解析

服务器返回的是一个字符串【实质是一个二维数组,在一个标签里面】

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=&quot;2088701258484254&quot;&amp;seller=&quot;2088701258484254&quot;&amp;out_trade_no=&quot;4598&quot;&amp;subject=&quot;机票&quot;&amp;body=&quot;航空机票信息&quot;&amp;total_fee=&quot;0.01&quot;&amp;notify_url=&quot;http://122.200.66.107:7772/stsf/RSANotifyReceiver&quot;&amp;success=&quot;false&quot;&amp;sign_type=&quot;RSA&quot;&amp;sign=&quot;CsH0dfGqamiZP3RP/bTSeeDWT+UjxBfYE3PIqobHOQ4LRy1uqZIVPy4PHiXDRtqcueksFe71v9lGlcS7Xh0cTZW0mNjY20EIG93sI/qewJPe1WvbhhAFTm4lZK4kNHokPEZRysJXntcw+LQm0Oci1WvROh/RVChDoaFToo2qz8w=&quot;}</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/">[[&quot;02&quot;,&quot;&#x652F;&#x4ED8;&#x5931;&#x8D25;&quot;]]</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;// 机票票号

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值