JSON与JAVA数据的转换(4)



6 json to xml
1)
JSONObject json = new JSONObject( true );
String xml = XMLSerializer.write( json );

<o null="true">

2)
JSONObject json = JSONObject.fromObject("{\"name\":\"json\",\"bool\":true,\"int\":1}");
String xml = XMLSerializer.write( json );
<o>
<name type="string">json</name>
<bool type="boolean">true</bool>
<int type="number">1</int>
</o>
<o>
<name type="string">json</name>
<bool type="boolean">true</bool>
<int type="number">1</int>
</o>
3)
JSONArray json = JSONArray.fromObject("[1,2,3]");
String xml = XMLSerializer.write( json );
<a>
<e type="number">1</e>
<e type="number">2</e>
<e type="number">3</e>
</a>

7 、xml to json
<a>
<e type="function" params="i,j">
return matrix[i][j];
</e>
</a>
<a>
<e type="function" params="i,j">
return matrix[i][j];
</e>
</a>

JSONArray json = (JSONArray) XMLSerializer.read( xml );
System.out.println( json );
// prints [function(i,j){ return matrix[i][j]; }]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzygzf.html