Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONArray


                lexer.nextToken();
                TreeSet<Object> treeSet = new TreeSet<Object>();
                parseArray(treeSet, fieldName);
                return treeSet;
            case LBRACKET:
                JSONArray array = new JSONArray();
                parseArray(array, fieldName);
                return array;
            case LBRACE:
                JSONObject object = new JSONObject();
                return parseObject(object, fieldName);
View Full Code Here


   * @return
   */
  @RequestMapping(params = "doExpandFileTree")
  @ResponseBody
  public Object doExpandFileTree(String parentNode){
    JSONArray fjson = new JSONArray();
    try{
      if(StringUtil.isEmpty(parentNode)){
        //返回磁盘驱动器根目录
        File[] roots = File.listRoots();
        for(File r:roots){
          JSONObject item = new JSONObject();
          item.put("id", r.getAbsolutePath());
          item.put("text", r.getPath());
          item.put("iconCls", "icon-folder");
          if(hasDirs(r)){
            item.put("state", "closed");
          }else{
            item.put("state", "open");
          }
          fjson.add(item);
        }
      }else{
        try {
          parentNode =  new String(parentNode.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e1) {
          e1.printStackTrace();
        }
        //返回子目录集
        File parent = new File(parentNode);
        File[] chs = parent.listFiles();
        for(File r:chs){
          JSONObject item = new JSONObject();
          if(r.isDirectory()){
            item.put("id", r.getAbsolutePath());
            item.put("text", r.getPath());
            if(hasDirs(r)){
              item.put("state", "closed");
            }else{
              item.put("state", "open");
            }
            fjson.add(item);
          }else{
           
          }
        }
      }
View Full Code Here

                    }

                    object.put(key, value);
                } else if (ch == '[') { // 减少潜套,兼容android
                    lexer.nextToken();
                    JSONArray list = new JSONArray();
                    this.parseArray(list, key);
                    value = list;
                    object.put(key, value);

                    if (lexer.token() == JSONToken.RBRACE) {
View Full Code Here

                    case LBRACE:
                        JSONObject object = new JSONObject();
                        value = parseObject(object, i);
                        break;
                    case LBRACKET:
                        Collection items = new JSONArray();
                        parseArray(items, i);
                        value = items;
                        break;
                    case NULL:
                        value = null;
View Full Code Here

                lexer.nextToken();
                TreeSet<Object> treeSet = new TreeSet<Object>();
                parseArray(treeSet, fieldName);
                return treeSet;
            case LBRACKET:
                JSONArray array = new JSONArray();
                parseArray(array, fieldName);
                return array;
            case LBRACE:
                JSONObject object = new JSONObject();
                return parseObject(object, fieldName);
View Full Code Here

        Family[] familyArray = new Family[] { fA, fB };
        String text = JSON.toJSONString(familyArray, true);
        System.out.println(text);

        JSONArray array = JSON.parseArray(text);

        Assert.assertSame(array.getJSONObject(0).get("master"), array.getJSONObject(0).getJSONArray("members").get(0));
       
        Family family = array.getObject(0, Family.class);
        Assert.assertNotNull(family.getMembers()[0]);
        Assert.assertNotNull(family.getMembers()[1]);
    }
View Full Code Here

   
    public void test_ex() throws Exception {
        RuntimeException ex = new RuntimeException();
        JSONObject object = (JSONObject) JSON.toJSON(ex);
        JSONArray array = object.getJSONArray("stackTrace");
        array.getJSONObject(0).put("lineNumber", null);
       
        JSON.parseObject(object.toJSONString(), Exception.class);
    }
View Full Code Here

            Assert.assertEquals(2, array.subList(2, 4).size());
        }
    }

    public void test_2() throws Exception {
        JSONArray array = new JSONArray();
        array.add(123);
        array.add("222");
        array.add(3);
        array.add(true);
        array.add("true");
        array.add(null);

        Assert.assertEquals(123, array.getByte(0).byteValue());
        Assert.assertEquals(123, array.getByteValue(0));

        Assert.assertEquals(123, array.getShort(0).shortValue());
        Assert.assertEquals(123, array.getShortValue(0));

        Assert.assertTrue(123F == array.getFloat(0).floatValue());
        Assert.assertTrue(123F == array.getFloatValue(0));

        Assert.assertTrue(123D == array.getDouble(0).doubleValue());
        Assert.assertTrue(123D == array.getDoubleValue(0));

        Assert.assertEquals(123, array.getIntValue(0));
        Assert.assertEquals(123, array.getLongValue(0));
        Assert.assertEquals(new BigDecimal("123"), array.getBigDecimal(0));

        Assert.assertEquals(222, array.getIntValue(1));
        Assert.assertEquals(new Integer(222), array.getInteger(1));
        Assert.assertEquals(new Long(222), array.getLong(1));
        Assert.assertEquals(new BigDecimal("222"), array.getBigDecimal(1));

        Assert.assertEquals(true, array.getBooleanValue(4));
        Assert.assertEquals(Boolean.TRUE, array.getBoolean(4));

        Assert.assertEquals(0, array.getIntValue(5));
        Assert.assertEquals(0, array.getLongValue(5));
        Assert.assertEquals(null, array.getInteger(5));
        Assert.assertEquals(null, array.getLong(5));
        Assert.assertEquals(null, array.getBigDecimal(5));
        Assert.assertEquals(null, array.getBoolean(5));
        Assert.assertEquals(false, array.getBooleanValue(5));
    }
View Full Code Here

        Assert.assertEquals(null, array.getBoolean(5));
        Assert.assertEquals(false, array.getBooleanValue(5));
    }

    public void test_getObject_null() throws Exception {
        JSONArray array = new JSONArray();
        array.add(null);

        Assert.assertTrue(array.getJSONObject(0) == null);
    }
View Full Code Here

        Assert.assertTrue(array.getJSONObject(0) == null);
    }

    public void test_getObject() throws Exception {
        JSONArray array = new JSONArray();
        array.add(new JSONObject());

        Assert.assertEquals(0, array.getJSONObject(0).size());
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.