<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<appid><![CDATA[wx2421b1c4370ec43b]]></appid>
<mch_id><![CDATA[10000100]]></mch_id>
<nonce_str><![CDATA[IITRi8Iabbblz1Jc]]></nonce_str>
<sign><![CDATA[7921E432F65EB8ED0CE9755F0E86D72F]]></sign>
<result_code><![CDATA[SUCCESS]]></result_code>
<prepay_id><![CDATA[wx201411101639507cbf6ffd8b0779950874]]></prepay_id>
<trade_type><![CDATA[JSAPI]]></trade_type>
</xml>
- /**
- *@description将xml字符串转换成map
- *@paramxml
- *@returnMap
- */
- publicstaticMap<String,String>readStringXmlOut(Stringxml){
- Map<String,String>map=newHashMap<String,String>();
- Documentdoc=null;
- try{
- doc=DocumentHelper.parseText(xml);//将字符串转为XML
- ElementrootElt=doc.getRootElement();//获取根节点
- List<Element>list=rootElt.elements();//获取根节点下所有节点
- for(Elementelement:list){//遍历节点
- map.put(element.getName(),element.getText());//节点的name为map的key,text为map的value
- }
- }catch(DocumentExceptione){
- e.printStackTrace();
- catch(Exceptione){
- returnmap;
- }
执行后
{
"return_code":"SUCCESS",
"return_msg":"OK",sans-serif; line-height:18px">"appid":"wx2421b1c4370ec43b",sans-serif; line-height:18px">"mch_id":"10000100",sans-serif; line-height:18px">"nonce_str":"IITRi8Iabbblz1Jc",sans-serif; line-height:18px">"sign":"7921E432F65EB8ED0CE9755F0E86D72F",sans-serif; line-height:18px">"result_code":"SUCCESS",sans-serif; line-height:18px">"prepay_id":"wx201411101639507cbf6ffd8b0779950874",sans-serif; line-height:18px">"trade_type":"JSAPI"
}