日期:2014-05-16  浏览次数:20366 次

JSON与JAVA的数据转换 json-->xml
6  json to xml
  1)
JSONObject json = new JSONObject( true );  
String xml = XMLSerializer.write( json ); 
< o class="object" null="true"> 
  2)
JSONObject json = JSONObject.fromObject("{"name":"json","bool":true,"int":1}");  
String xml = XMLSerializer.write( json ); 
< o class="object"> 
   < name type="string">json< /name> 
   < bool type="boolean">true< /bool> 
   < int type="number">1< /int> 
< /o> 
   < o class="object"> 
      < 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 class="array"> 
   < e type="number">1< /e> 
   < e type="number">2< /e> 
   < e type="number">3< /e> 
< /a>