第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Java中將JSON轉(zhuǎn)換為XML

在Java中將JSON轉(zhuǎn)換為XML

函數(shù)式編程 2019-10-29 12:50:31
我是json的新手。我有一個程序可以從json對象生成xml。String str = "{'name':'JSON','integer':1,'double':2.0,'boolean':true,'nested':{'id':42},'array':[1,2,3]}";      JSON json = JSONSerializer.toJSON( str );      XMLSerializer xmlSerializer = new XMLSerializer();      xmlSerializer.setTypeHintsCompatibility( false );      String xml = xmlSerializer.write( json );      System.out.println(xml); 輸出為:<?xml version="1.0" encoding="UTF-8"?><o><array json_class="array"><e json_type="number">1</e><e json_type="number">2</e><e json_type="number">3</e></array><boolean json_type="boolean">true</boolean><double json_type="number">2.0</double><integer json_type="number">1</integer><name json_type="string">JSON</name><nested json_class="object"><id json_type="number">42</id></nested></o>我最大的問題是如何編寫自己的屬性而不是json_type =“ number”,以及如何編寫自己的子元素,例如。
查看完整描述

3 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗 獲得超8個贊

Underscore-java庫具有靜態(tài)方法U.jsonToXml(jsonstring)。我是該項目的維護者?,F(xiàn)場例子


import com.github.underscore.lodash.U;


public class MyClass {

    public static void main(String args[]) {

        String json = "{\"name\":\"JSON\",\"integer\":1,\"double\":2.0,\"boolean\":true,\"nested\":{\"id\":42},\"array\":[1,2,3]}";  

        System.out.println(json); 

        String xml = U.jsonToXml(json);  

        System.out.println(xml); 

    }

}

輸出:


{"name":"JSON","integer":1,"double":2.0,"boolean":true,"nested":{"id":42},"array":[1,2,3]}

<?xml version="1.0" encoding="UTF-8"?>

<root>

  <name>JSON</name>

  <integer number="true">1</integer>

  <double number="true">2.0</double>

  <boolean boolean="true">true</boolean>

  <nested>

    <id number="true">42</id>

  </nested>

  <array number="true">1</array>

  <array number="true">2</array>

  <array number="true">3</array>

</root>


查看完整回答
反對 回復(fù) 2019-10-29
  • 3 回答
  • 0 關(guān)注
  • 616 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號