soap消息轉成json。


public static String parserXml(String strXml) {
        String json="";
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new InputSource(new StringReader(strXml)));
            NodeList sessions = document.getChildNodes();
            /*HashMap<String,String> hash=new HashMap<String,String>();*/

            for (int i = 0; i < sessions.getLength(); i++) {
                Node session = sessions.item(i);
                NodeList sessionInfo = session.getChildNodes();
                for (int j = 0; j < sessionInfo.getLength(); j++) {
                    Node node = sessionInfo.item(j);
                    NodeList sessionMeta = node.getChildNodes();
                    for (int k = 0; k < sessionMeta.getLength(); k++) {
                        System.out.println(sessionMeta.item(k).getTextContent());
                        json=sessionMeta.item(k).getTextContent();
                        // hash.put(sessionMeta.item(k).getNodeName(), sessionMeta.item(k).getTextContent());
                    }
                }
            }
        //    System.out.println("獲取json"+json);
//            try {
//                JSONObject result=new JSONObject(json);
//                //result.get("message");
//                //result.get("statusCode");
//                if(result.get("statusCode").equals("S")) {
//                    System.out.println(result.get("message"));
//                }else {
//                    System.out.println("失敗");
//                }
//            } catch (JSONException e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }

            System.out.println("解析完畢");
        } catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
        } catch (ParserConfigurationException e) {
            System.out.println(e.getMessage());
        } catch (SAXException e) {
            System.out.println(e.getMessage());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return json;
    }

 

String json=SmpClient.parserXml(result);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM