精华内容
参与话题
问答
  • JSONArray

    2019-09-03 21:50:23
    HttpResponse<String> response = Unirest.post("http://getDevice").fields(mapData).asString... result = response.getBody(); JSONArray myJsonArray = JSONArray.parseArray(result); myJsonArray.stre...
    HttpResponse<String> response = Unirest.post("http://getDevice").fields(mapData).asString();
    result = response.getBody();
    JSONArray myJsonArray = JSONArray.parseArray(result);
    
    myJsonArray.stream().forEach(item -> {
     JSONObject jb = (JSONObject) item;
     int SUBSECT_ID = jb.getInteger("SUBSECT_ID");
     int AVGSPEED = jb.getInteger("AVGSPEED");
     String SUBSECT_NAME = jb.getString("SUBSECT_NAME");
     System.out.println(SUBSECT_NAME);
    });
    展开全文
  • jsonArray

    2019-04-28 14:49:35
    JSONArray ret={"object":{"disciple":[{"id":16,"username":"2345","profitdelivering":2.0},{"id":17,"username":"qwer","profitdelivering":1.0}],"sun":3.0},"resultdesc":"查询成功!","success":true} ret....

    JSONArray ret={"object":{"disciple":[{"id":16,"username":"2345","profitdelivering":2.0},{"id":17,"username":"qwer","profitdelivering":1.0}],"sun":3.0},"resultdesc":"查询成功!","success":true}

    ret.getObject()输出为

    [{id=16, username=2345, profitdelivering=2.0}, {id=17, username=qwer, profitdelivering=1.0}]

    一个jsonArray

    List<Map<String, Object>> arr = (List<Map<String, Object>>) ret.getObject();
    //sum 
    double sun = 0.00;
    for (int i = 0; i < arr.size(); i++) {
        sun += (double) arr.get(i).get("profitdelivering");
    }
    展开全文
  • JsonArray

    2013-03-20 13:43:50
    简单说说Json数组,见如下实例: package com.json.jsonarray; import ...import org.apache.commons.lang.StringEscapeUtils;...import org.json.simple.JSONArray; import org.json.simple.J...
    简单说说Json数组,见如下实例:


    package com.json.jsonarray;

    import net.sf.json.JSONObject;

    import org.apache.commons.lang.StringEscapeUtils;
    import org.json.simple.JSONArray;
    import org.json.simple.JSONValue;

    public class JsonArrayTest {


    public static void main(String[] args) {
    String s = "[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
    Object obj = JSONValue.parse(s);
    JSONArray array = (JSONArray) obj;
    System.out.println(array.get(0));
    System.out.println(array.get(1));

    /*
    *
    String str = "{\"params\":[{\"field0\":\"NAME\",\"operateflag0\":\"@contain#\",\"searchcontant0\":\"北\",\"logic0\":\"and\"}, {\"field1\":\"ID\",\"operateflag1\":\"@contain#\",\"searchcontant1\":\"1\",\"logic1\":\"or\"},{\"field2\":\"SEQUENCE\",\"operateflag2\":\"@contain#\",\"searchcontant2\":\"5\"}]}";
    System.out.println("接收到的字符串:" + str);
    // 将json字符串转成json对象
    JSONObject jb = JSONObject.fromObject(str);
    // 取查询参数params,是个json数组
    net.sf.json.JSONArray jsons = jb.getJSONArray("params");
    int jsonLength = jsons.size();
    // 对json数组进行循环

    for (int i = 0; i < jsonLength; i++) {
    JSONObject tempJson = JSONObject.fromObject(jsons.get(i));
    System.out.println("ddd:" + tempJson);
    String field = StringEscapeUtils.escapeSql(tempJson
    .getString("field" + i));
    String operateFlag = StringEscapeUtils.escapeSql(tempJson
    .getString("operateflag" + i));
    String searchContant = StringEscapeUtils.escapeSql(tempJson
    .getString("searchcontant" + i));
    String logic = StringEscapeUtils.escapeSql(tempJson
    .getString("logic" + i));
    }
    */


    }
    }

    以上代码复制就可以运行。
    展开全文
  • JSONARRAY

    千次阅读 2012-01-10 23:59:09
    json array: public ActionForward findEmpByDepid(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated

    json array:

    public ActionForward findEmpByDepid(ActionMapping mapping, ActionForm form,
    			HttpServletRequest request, HttpServletResponse response)
    			throws Exception {
    		// TODO Auto-generated method stub
    		String depid=request.getParameter("depid");
    		List<Emp> list=empService.findByDepId(Integer.parseInt(depid));
    		JsonConfig config=new JsonConfig();
    		
    		config.registerJsonValueProcessor(Date.class,new JsonValueProcessor() {
    			
    			public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
    				// TODO Auto-generated method stub
    				SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
    				return sd.format((Date)arg1);
    			}
    			
    			public Object processArrayValue(Object arg0, JsonConfig arg1) {
    				// TODO Auto-generated method stub
    				return null;
    			}
    		});
    		//忽略属性
    		config.setExcludes(new String[]{"dep"});
    		
    		JSONArray arr=JSONArray.fromObject(list,config);
    	
    		response.getWriter().print(arr);
    		return null;
    	}
     
    public ActionForward updateEmp(ActionMapping mapping, ActionForm form,
    			HttpServletRequest request, HttpServletResponse response)
    			throws Exception {
    		String json=request.getParameter("json");
    		//将字符串转换成对象
    		JSONObject obj=JSONObject.fromObject(json);
    		//将JsonObject转换成pojo
    		Emp emp=(Emp) JSONObject.toBean(obj,Emp.class);
    		
    		int depid=obj.getInt("depid");
    		
    		try {
    			empService.update(emp, depid);
    			response.getWriter().print("{result:true}");
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    			response.getWriter().print("{result:false}");
    		}
    		return null;
    	}
     
     
    /**
    	 * xml 优点:描述数据比较准确,缺点:数据量大
    	 * json 优点:数据量小,
    	 * 
    	 * json的序列化和反序列化
    	 * json->java对象	反序列化
    	 * java->json 序列化
    	 * json的语法规则
    	 * 
    	 * 
    	 * 
    	 * 单一对象
    	 * {属性1:值1,属性2:值2}
    	 * 
    	 * 数组对象 (重复对象)
    	 * [{属性1:值1,属性2:值2},{属性1:值1,属性2:值2}]
    	 * 数组不同对象
    	 * {对象名1:{属性1:值1,属性2:值2},对象名2:{属性3:值3,属性4:值4}}
    	 * 
    	 */
    	public void doPost(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    //		String str="{name:'张三',money:100}";
    //		String str="[{name:'张三',money:100},{name:'李四',money:200}]";
    //		String str="{stu:{stuname:'张三',stumoney:100},tea:{teaname:'李四',teamoney:200}}";
    		
    		//  {stu:{stuname:'张三',stumoney:100},stu:{stuname:'张三',stumoney:100},result:true}
    		
    		
    		
    		request.setCharacterEncoding("UTF-8");
    		response.setContentType("text/html;charset=UTF-8");
    		String p=request.getParameter("p");
    		System.out.println(p);
    		
    		//设置反序列化的日期转换  字符串变对象
    		JSONUtils.getMorpherRegistry().registerMorpher(
    				new DateMorpher(new String[] {"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"})
    			);  
    		
    		
    		/*
    		 * json的序列化
    		 * 对象转换成字符串
    		 * 
    		 * 
    		 */
    		Student stu1=new Student("李四", new Date(), 200);
    		//获得json的配置
    		JsonConfig config=new JsonConfig();
    		//注册一个json对象的转换器,如果转换Date类型,调用该转换器
    		config.registerJsonValueProcessor(Date.class,new JsonValueProcessor() {
    			public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
    				// TODO Auto-generated method stub
    				if("birthday".equals(arg0)){
    					SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    					Date d=(Date) arg1;
    					return sd.format(d);
    				}
    				return null;
    			}
    			public Object processArrayValue(Object arg0, JsonConfig arg1) {
    				// TODO Auto-generated method stub
    				return null;
    			}
    		});
    		
    		JSONObject jsonObject=JSONObject.fromObject(stu1,config);
    		//json字符串
    		System.out.println(jsonObject);
    		
    		
    		
    		
    		List list1=new ArrayList();
    		JSONArray arr1=JSONArray.fromObject(list1);
    		//json字符串
    		System.out.println(arr1);
    		
    		
    		
    		
    		
    		
    		
    		//使用json-lib进行对象的反序列化
    		//转换日期 ,
    		
    		
    		
    		//将字符串转换成jsonObject对象
    		//单一对象
    //		JSONObject obj=JSONObject.fromObject(p);
    //		//将jsonObject转换成java对象
    //		Student stu=(Student) JSONObject.toBean(obj,Student.class);
    //		System.out.println(stu.getName());
    //		System.out.println(stu.getMoney());
    //		System.out.println(stu.getBirthday());
    		
    		
    		JSONArray arr=JSONArray.fromObject(p);
    		JsonConfig config1=new JsonConfig();
    		List<Student> list= JSONArray.toList(arr,Student.class);
    		for (Student student : list) {
    			System.out.println(student.getName());
    			System.out.println(student.getBirthday());
    		}
    		
    	}
    
    }




     

    展开全文
  • fastjson List转JSONArray以及JSONArray转List

    万次阅读 多人点赞 2018-05-31 11:25:54
    1.fastjson List转JSONArrayList&lt;T&gt; list = new ArrayList&lt;T&gt;();JSONArray array= JSONArray.parseArray...2.fastjson JSONArray转ListJSONArray array = new JSONArray();List&...
  • List转JSONArrayJSONArray转List

    万次阅读 2019-08-19 20:59:33
    1.List转JSONArray List<T> list = new ArrayList<T>(); JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); 2.JSONArray转List JSONArray array = new JSONArray(); List<...
  • JSONArray 嵌套JSONArray 取值

    千次阅读 2017-11-01 09:03:50
    JSONArray数组嵌套取值JSONArray
  • JsonArray 遍历

    千次阅读 2015-08-24 11:22:36
    JsonArray
  • JSONArray jsonArray解析

    千次阅读 2013-11-14 17:23:41
    try { JSONArray jsonArray = new JSONObject(serviceMessage).getJSONArray("candidateList"); for(int i=0; i<jsonArray.length(); i++){ JSONObject jsonObject = (JSON
  • JSONArray删除

    2020-09-09 20:36:28
    JSONArray遍历删除 java 复杂的JSONArray遍历思路 ​ 总结就4个字:先删后加 ​ 删除时需要注意index,根据特定的目标对象删除后,需要将删除过对象后的数组保存下来,组装可以覆盖原来位置的对象然后添加进...
  • JSONArray jsonArray for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Set<String> keys = jsonObject.keySet(); for (String curKey : keys) { ...
  • jsonArray 排序

    2019-09-12 07:36:55
    jsonArray 排序,网上百度,一般都是转为 list 进行排序,其实不需要的。 我的理解是, jsonArray 本质上还是一个 list . 所以是可以使用 集合的 sort 方法的。 JSONArray jsonArray = xxx.xxx(); // Collect.....
  • 1.fastjson List转JSONArray List list = new ArrayList(); JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); 2.fastjson JSONArray转List JSONArray array = new JSONArray(); List list = ...
  • JSONArray和JSONObject

    2014-05-07 22:15:45
    JSONArray
  • JSONArray转List

    万次阅读 2019-02-22 14:18:18
    JSONArray转String,用到 JSONObject 的静态方法 toJSONString String jsonStr = JSONObject.toJSONString(jsonArray); String转List,用到 JSONObject 的静态方法 parseArray List&lt;MyClass&gt; ...
  • JSONArray排序

    2019-01-10 12:02:00
    JSONArray根据某个key进行排序,注意key的类型。 1、只支持JDK1.8以上版本 private static JSONArray sortProxyAndCdn(JSONArray bindArrayResult) { System.out.println("排序前:"+bindArrayResult); ...
  • 遍历 JSONArray

    千次阅读 2019-08-22 18:23:12
    JSONArray ret = XXX; for (int i = 0; i < ret.size(); i++) { JSONObject d = ret.getJSONObject(i);// 遍历 jsonarray 数组,把每一个对象转成 json 对象 System.out.println(d.get("xxx"...
  • @List转JSONArrayJSONArray转List 1.List转JSONArray List list = new ArrayList(); JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); 2.JSONArray转List JSONArray array = new JSONArray(); ...
  • JSONArray遍历

    2020-06-19 10:52:20
    需要把json数组JSONArray对象进行遍历、转换为map对象 二.需求分析: 1.首先我想到的是直接遍历,通过JSONObject对象获取指定k的v值 for (JSONObject a : jsonArray){ list.add(a.get("k")) } 但是编译异常...
  • 遍历jsonArray

    千次阅读 2017-02-08 09:30:59
    JSONArray jsonArrayjsonArray = JSONArray.fromObject(data); for(int i=0;i Object object=jsonArray.get(i); JSONObject jsonObject=JSONObject.fromObject(object); String parentId=jsonObject.get
  • 1.fastjsonList转JSONArray List<T> list = new ArrayList<T>(); JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); 2.fastjsonJSONArray转List JSONArray array = new JSONArray()....

空空如也

1 2 3 4 5 ... 20
收藏数 9,402
精华内容 3,760
关键字:

jsonarray