`
nannan408
  • 浏览: 1755502 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

架构师之--------通讯传输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"));

	}

}
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics