json to xml
2021-06-16 07:02
                         标签:net   org   class   int   getjson   main   XML   instance   csdn    package com.yile.test; 	public class Xml2JsonTest {   	    public static void testOrgJSon(){   	    public static void testXmlSerializer(){     http://blog.csdn.net/lom9357bye/article/details/53291994 http://blog.csdn.net/lom9357bye/article/details/53291994 json to xml 标签:net   org   class   int   getjson   main   XML   instance   csdn    原文地址:http://www.cnblogs.com/Lennyyi/p/7271540.html
	import org.json.XML;  
	import net.sf.json.JSONObject;  
	import net.sf.json.xml.XMLSerializer;  
	    private static String xml = "
	    public static void main(String[] args) {  
	        testOrgJSon();  
	        testXmlSerializer();  
	    }  
	        org.json.JSONObject jsonObj = XML.toJSONObject(xml);  
	        System.out.println("org.json xml2json:"+jsonObj);  
	        org.json.JSONObject user = jsonObj.getJSONObject("root").getJSONObject("user");//org.json需去除根标签  
	        System.out.println("用户名:"+user.getString("name"));  
	        System.out.println("性别:"+user.getString("sex"));  
	    }  
	        XMLSerializer xmlSerializer = new XMLSerializer();  
	        JSONObject jsonObject = (JSONObject)xmlSerializer.read(xml);  
	        System.out.println("json-lib xml2json result: "+jsonObject);  
	        JSONObject user = jsonObject.getJSONObject("user");  
	        System.out.println("用户名:"+user.get("name"));  
	        System.out.println("性别:"+(user.get("sex") instanceof String ? user.getString("sex"):""));  
	    }  
下一篇:js常用内置对象及方法