架构师之--------通讯传输json原生态通用转换和逆转换

1.前言.

至少要用到jar包json-lib-2.4-jdk15.jar.

2.例子.

 
import java.io.UnsupportedEncodingException;
import net.sf.json.JSONObject;


public class test {
	public static void main(String[] args) throws UnsupportedEncodingException {
		
		JSONObject jsonObject=new JSONObject();
		JSONObject jsonObject1=new JSONObject();
		jsonObject1.accumulate("kk1", "few");
		jsonObject1.accumulate("kk2", "few");
		jsonObject.accumulate("kkk", "kkk");
		jsonObject.accumulate("json", jsonObject1);
		
		
		//System.out.println("住"jsonObject.toString());
		
		String jString=jsonObject.toString();
		System.out.println("转换前:"+jsonObject.toString());
		System.out.println("转换后的子objec"+(JSONObject)JSONObject.fromObject(jString).getJSONObject("json"));

	}

}

相关推荐