json put accumulate element 区别

来源:互联网 发布:下载office for mac 编辑:程序博客网 时间:2024/06/07 16:10
      JSONObject jsonObject = new JSONObject();      jsonObject.put("1", "2");      jsonObject.put("1", "3");      System.out.println(jsonObject.toString());

此时打印结果为:{"1":"3"}   put直接替换key指向的value

      jsonObject.accumulate("1", "4");      System.out.println(jsonObject.toString());

打印结果 {"1":["3","4"]}    accumulate  添加value不替换  到key


      Object object = null;      jsonObject.element("1", object);      System.out.println(jsonObject.toString());

打印结果:{}     element  如果value为空值   key也被移除         

而如果是accumulate  方法 则会在value后面加一个null元素   {"1":["3","4",null]}

0 0