zoukankan      html  css  js  c++  java
  • XML 字符串 转 JSON

    package com.yile.test;

    import com.google.gson.Gson;
    import com.thoughtworks.xstream.XStream;
    import com.thoughtworks.xstream.io.xml.DomDriver;
    import com.yile.model.Product;

    public class XStreamTest {
    public static void main(String[] args) {

    XStream xstream = new XStream(new DomDriver());

    //设置了这个别名才能识别下面 xml 中的 product 节点,否则要用类全限名称
    xstream.alias("product", Product.class);
    String xml = "<product><prodId>1001</prodId><prodName>电脑" +
    "</prodName><prodPrice>4000.0</prodPrice></product>";
    Product prod = (Product)xstream.fromXML(xml);
    Gson gson = new Gson();
    String proStr = gson.toJson(prod);
    System.out.println(proStr);
    }
    }

    JARS:

    cglib-nodep-3.2.5.jar
    dom4j-1.6.1.jar
    gson-2.8.1.jar
    jdom-2.0.2.jar
    jdom2-2.0.6.jar
    jettison-1.3.8.jar
    joda-time-2.9.9.jar
    kxml2-2.3.0.jar
    kxml2-min-2.3.0.jar
    stax-api-1.0-2.jar
    woodstox-core-asl-4.4.1.jar
    xmlpull-1.1.3.1.jar
    xom-1.2.10.jar
    xpp3_min-1.1.4c.jar
    xstream-1.4.10.jar

  • 相关阅读:
    Prim+堆优化
    Tarjan缩点+建新图
    CF482A
    CF545C
    CF570B
    Python 入门2 list介绍
    Python 入门1 上传代码
    黑客与画家 第十三章
    黑客与画家 第十一章
    黑客与画家 第五章
  • 原文地址:https://www.cnblogs.com/Lennyyi/p/7271441.html
Copyright © 2011-2022 走看看