zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    grep awk 搜索日志常用命令
    【MySQL】通过Percona Monitoring and Management实现数据库的监控
    阿里云centos7.4安装nexus
    Java 开源博客 Solo 1.8.0 发布
    《设计模式之美》
    《设计模式之美》
    《设计模式之美》
    《设计模式之美》
    iOS 通过反射的方式调用目标函数
    回调方法?钩子方法?模板模式?
  • 原文地址:https://www.cnblogs.com/1ming/p/15564338.html
Copyright © 2011-2022 走看看