zoukankan      html  css  js  c++  java
  • xml和json之间的转换

    /**
    * xml转json
    * @author yizw
    *
    */
    public class XmlExercise {

    /**
    * 将xml字符串<STRONG>转换</STRONG>为JSON字符串
    *
    * @param xmlString
    * xml字符串
    * @return JSON<STRONG>对象</STRONG>
    */
    public static String xml2json(String xmlString) {
    XMLSerializer xmlSerializer = new XMLSerializer();
    JSON json = xmlSerializer.read(xmlString);
    return json.toString(1);
    }

    /**
    * 将xmlDocument<STRONG>转换</STRONG>为JSON<STRONG>对象</STRONG>
    *
    * @param xmlDocument
    * XML Document
    * @return JSON<STRONG>对象</STRONG>
    */
    public static String xml2json(Document xmlDocument) {
    return xml2json(xmlDocument.toString());
    }

    /**
    * JSON(数组)字符串<STRONG>转换</STRONG>成XML字符串
    *
    * @param jsonString
    * @return
    */
    public static String json2xml(String jsonString) {
    XMLSerializer xmlSerializer = new XMLSerializer();
    return xmlSerializer.write(JSONSerializer.toJSON(jsonString));
    // return xmlSerializer.write(JSONArray.fromObject(jsonString));//这种方式只支持JSON数组
    }


    }

  • 相关阅读:
    zookeeper部署
    Hadoop集群的构建和安装
    numpy ndarray求其最值的索引
    两数之和
    盛最多水的容器
    mysql 单表卡死
    Leetcode 258. Add Digits
    Matlab中添加路径与去除路径
    Leetcode 136 Single Number
    Leetcode 485. Max Consecutive Ones
  • 原文地址:https://www.cnblogs.com/yizw/p/7993085.html
Copyright © 2011-2022 走看看