package nwpu.precisefunds.uploadfile;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class TestClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
JSONObject jo = new JSONObject();
jo.put("isleaf", true);
jo.put("name", "张三");
jo.put("age", "25");
JSONObject jo2 = new JSONObject();
jo2.put("isleaf", false);
jo2.put("name", "李四");
jo2.put("age", "25");
/*JSONArray jr= new JSONArray();
Map<String, String> member = new HashMap<String, String>();
member.put("famName:","甲");
member.put("famAge:","甲哈");
member.put("relation:","甲系" );
jr.put(member);
*/
JSONObject jo3 = new JSONObject();
jo3.put("isleaf", true);
jo3.put("name", "王五");
jo3.put("age", "25");
/*jo3.put("isleaf", false);
jo3.put("name", "赵六");
jo3.put("isleaf", 28);*/
JSONArray ja0 = new JSONArray();
// 把JSONObject添加到中JSONArray
ja0.add(jo3);
ja0.add(jo);
// 把JSONArray添加到JSONObject中
jo2.element("children", ja0);
System.out.println(jo2.toString());
JSONArray ja1 = new JSONArray();
ja1.add(jo);
ja1.add(jo2);
ja1.add(jo3);
System.out.println("===========================1========+++++++++++++++++++++");
System.out.println("最终格式"+ja1.toString());
System.out.println("===========================2=======+++++++++++++++++++++");
}
}
JSONArray和JSONObject 区别及测试实例
最新推荐文章于 2023-09-25 14:11:14 发布