JSONArray和JSONObject 区别及测试实例

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=======+++++++++++++++++++++");

	}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值