java 使用map返回多个对象组装

                Object json=JSONObject.fromObject("{}");
		List<Object> list = new ArrayList<Object>();
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
		list.add("5");
		list.add("6");
		List<Object> result = new ArrayList<Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		for(Object str :list){
			map.put("name", str);
			map.put("age", str);
			result.add(map);
		}
		JSONArray arr=JSONArray.fromObject(result);
		if(arr!=null){
			json=arr;
		}
		System.out.println(arr);

  输出值格式为:[{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"}]

posted @ 2016-05-10 11:12  小安妮的熊  Views(3627)  Comments(0Edit  收藏  举报