jsonObject 用法

1. JSONObject jsonObj = new JSONObject().fromObject(bean);

   	GysDogBean bean = new GysDogBean(); 
		try {
			queryCondition = Util.URLDecoder(queryCondition);
			bean = RosDao.getGysDogBeanByLockId(queryCondition);
		} catch (Exception e) {
			e.printStackTrace();
		}
		JSONObject jsonObj = new JSONObject().fromObject(bean);
        System.out.println(jsonObj.toString());

 

2.  json.put("TF", "success");

 

3. JSONArray jsonObj = new JSONArray().fromObject(json_list);

   

         List<Map<String, Object>> json_list = new ArrayList<Map<String,Object>>();
    	  if (id.equals("-1")){
    		  List<MapData> list = RosDao.getCgzzList();
    		  Map<String, Object> map;
    		  for (MapData map_data : list){
    			  map = Util.makeTree(map_data.getValue(), map_data.getKey(), "close");
    			  json_list.add(map);
    		  }
    	  }
    	
          Map<String, Object> map;
          JSONArray jsonObj = new JSONArray().fromObject(json_list);
          System.out.println(jsonObj.toString());

 

4.     jsonObj.put("rows", json_list);

    

 

      List<Map<String, Object>> json_list = new ArrayList<Map<String,Object>>();
       Map<String, Object> map;
       
       int i = 1;
       for (JbxxBean jbxxbean : jbxxbean_list){
     	  map = new HashMap<String, Object>();
     	  map.put("id", jbxxbean.getLIFNRRGTID());
     	  //序号
     	 // map.put("LIFNRRGTID", jbxxbean.getLIFNRRGTID());
     	  map.put("NAME1", jbxxbean.getNAME1()); 
     	  map.put("GYSDMUD", jbxxbean.getGYSDMUD());
     	  json_list.add(map);
     	  i ++;
       }
       jsonObj.put("rows", json_list);
       System.out.println(jsonObj.toString());

 

   

 

你可能感兴趣的:(JSONObject)