• 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);
  • 相关阅读:
    Python中yield和yield from区别
    Python基础05编码问题
    Python eval()函数
    Python异常大全
    Python基础08 内置函数
    Python os和sys模块基本操作
    git学习(3)-本地标签管理
    ubuntu 安装 node 以及升级更新到最新版本
    git学习(2)-分支管理
    git学习(1)-git基础
  • 原文地址:https://www.cnblogs.com/1ming/p/15564338.html
Copyright © 2020-2023  润新知