html tool

2017年10月12日星期四

json - java - org.json


http://blog.csdn.net/flyliuweisky547/article/details/19172133

[popexizhi:
确实很好用,记录一下
]


[java] view plain copy
  1. package TestJson;  
  2.   
  3. import org.json.JSONObject;  
  4.   
  5. public class TestJson03 {  
  6.     public static void main(String[] args) {  
  7.         //解析字符串  
  8.         JSONObject jsonObject1 = new JSONObject();  
  9.         jsonObject1.put("Name""Tom");  
  10.         jsonObject1.put("age""11");  
  11.         System.out.println("解析字符串:" + "\r" + jsonObject1.getString("Name"));  
  12.           
  13.         //解析对象  
  14.         JSONObject jsonObject = new JSONObject("{'Name':'Tom','age':'11'}");  
  15.         JSONObject jsonObject2 = new JSONObject();  
  16.         jsonObject2.put("jsonObject", jsonObject);  
  17.           
  18.         System.out.println("解析对象:");  
  19.         System.out.println(jsonObject2.getJSONObject("jsonObject").toString());  
  20.     }  
  21.   
  22. }  
Output:

[plain] view plain copy
  1. 解析字符串:  
  2. Tom  
  3. 解析对象:  
  4. {"Name":"Tom","age":"11"}  

没有评论:

发表评论