XML 字串 轉 JSON

來源:互聯網
上載者:User

標籤:別名   drive   pack   識別   imp   on()   oda   1.2   oid   

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

XML 字串 轉 JSON

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.