当前位置: 首页>>代码示例>>Java>>正文


Java DefaultJSONParser.parseArray方法代码示例

本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.parseArray方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.parseArray方法的具体用法?Java DefaultJSONParser.parseArray怎么用?Java DefaultJSONParser.parseArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.fastjson.parser.DefaultJSONParser的用法示例。


在下文中一共展示了DefaultJSONParser.parseArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    if (parser.lexer.token() == JSONToken.NULL) {
        parser.lexer.nextToken(JSONToken.COMMA);
        return null;
    }
    
    if (type == JSONArray.class) {
        JSONArray array = new JSONArray();
        parser.parseArray(array);
        return (T) array;
    }

    Collection list = TypeUtils.createCollection(type);

    Type itemType = TypeUtils.getCollectionItemType(type);
    parser.parseArray(itemType, list, fieldName);

    return (T) list;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:CollectionCodec.java

示例2: parseArray

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static final <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
        return null;
    }
    List<T> list;
    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken();
        list = null;
    } else {
        Collection list2 = new ArrayList();
        parser.parseArray((Class) clazz, list2);
        parser.handleResovleTask(list2);
    }
    parser.close();
    return list;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:JSON.java

示例3: test_scanInt

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_scanInt() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 1024; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        buf.append("{\"id\":" + i + "}");
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    List<VO> array = parser.parseArray(VO.class);
    for (int i = 0; i < array.size(); ++i) {
        Assert.assertEquals(i, array.get(i).getId());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:JSONReaderScannerTest__entity_int.java

示例4: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    if (parser.getLexer().token() == JSONToken.NULL) {
        parser.getLexer().nextToken(JSONToken.COMMA);
        return null;
    }

    JSONArray array = new JSONArray();
    parser.parseArray(array);

    AtomicLongArray atomicArray = new AtomicLongArray(array.size());
    for (int i = 0; i < array.size(); ++i) {
        atomicArray.set(i, array.getLong(i));
    }

    return (T) atomicArray;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:AtomicLongArrayCodec.java

示例5: test_scanInt

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_scanInt() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 10; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        //1000000000000
        //
        buf.append("{\"id\":\"" + i + "\"}");
        
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    List<VO> array = parser.parseArray(VO.class);
    for (int i = 0; i < array.size(); ++i) {
        Assert.assertEquals(Integer.toString(i), array.get(i).getId()); 
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:JSONReaderScannerTest__entity_string.java

示例6: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    if (parser.getLexer().token() == JSONToken.NULL) {
        parser.getLexer().nextToken(JSONToken.COMMA);
        return null;
    }

    JSONArray array = new JSONArray();
    parser.parseArray(array);

    AtomicIntegerArray atomicArray = new AtomicIntegerArray(array.size());
    for (int i = 0; i < array.size(); ++i) {
        atomicArray.set(i, array.getInteger(i));
    }

    return (T) atomicArray;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:AtomicIntegerArrayCodec.java

示例7: test_error_var

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_var() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,2,null }");
    parser.config(Feature.AllowISO8601DateFormat, false);

    Exception error = null;
    try {
        Object[] array = parser.parseArray(new Type[] { Integer[].class });
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DefaultExtJSONParser_parseArray.java

示例8: test_error_4

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_4() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,null }");
    parser.config(Feature.AllowISO8601DateFormat, false);

    Exception error = null;
    try {
        parser.parseArray(new Type[] { String.class });
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DefaultExtJSONParser_parseArray.java

示例9: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    if (!(type instanceof GenericArrayType)) {
        return parser.parse(fieldName);
    }
    Type componentType = ((GenericArrayType) type).getGenericComponentType();
    if (componentType instanceof TypeVariable) {
        componentType = ((TypeVariable) componentType).getBounds()[0];
    }
    Object list = new ArrayList();
    parser.parseArray(componentType, (Collection) list);
    if (!(componentType instanceof Class)) {
        return list.toArray();
    }
    Class<?> componentClass = (Class) componentType;
    if (componentClass == Boolean.TYPE) {
        return TypeUtils.cast(list, boolean[].class, parser.getConfig());
    }
    if (componentClass == Short.TYPE) {
        return TypeUtils.cast(list, short[].class, parser.getConfig());
    }
    if (componentClass == Integer.TYPE) {
        return TypeUtils.cast(list, int[].class, parser.getConfig());
    }
    if (componentClass == Long.TYPE) {
        return TypeUtils.cast(list, long[].class, parser.getConfig());
    }
    if (componentClass == Float.TYPE) {
        return TypeUtils.cast(list, float[].class, parser.getConfig());
    }
    if (componentClass == Double.TYPE) {
        return TypeUtils.cast(list, double[].class, parser.getConfig());
    }
    Object[] array = (Object[]) Array.newInstance(componentClass, list.size());
    list.toArray(array);
    return array;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:37,代码来源:JavaObjectDeserializer.java

示例10: test_scanInt

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_scanInt() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 10; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        //1000000000000
        //
        if (i % 2 == 0) {
            buf.append("{\"id\":true}");    
        } else {
            buf.append("{\"id\":false}");
        }
        
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    List<VO> array = parser.parseArray(VO.class);
    for (int i = 0; i < array.size(); ++i) {
        if (i % 2 == 0) {
            Assert.assertEquals(true, array.get(i).getId());    
        } else {
            Assert.assertEquals(false, array.get(i).getId());
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:JSONReaderScannerTest__entity_boolean.java

示例11: test_error_3

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_3() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,null }");
    ArrayList list = new ArrayList();
    parser.config(Feature.AllowISO8601DateFormat, false);

    Exception error = null;
    try {
        parser.parseArray(String.class, list);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:DefaultExtJSONParser_parseArray.java

示例12: test_5

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_5() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,2,3,null]");
    Object[] array = parser.parseArray(new Type[] { Integer.class, BigDecimal.class, Long.class, String.class });
    Assert.assertEquals(new Integer(1), array[0]);
    Assert.assertEquals(new BigDecimal("2"), array[1]);
    Assert.assertEquals(new Long(3), array[2]);
    Assert.assertEquals(null, array[3]);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:DefaultExtJSONParser_parseArray.java

示例13: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    if (type instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType) type).getGenericComponentType();
        if (componentType instanceof TypeVariable) {
            TypeVariable<?> componentVar = (TypeVariable<?>) componentType;
            componentType = componentVar.getBounds()[0];
        }

        List<Object> list = new ArrayList<Object>();
        parser.parseArray(componentType, list);
        Class<?> componentClass;
        if (componentType instanceof Class) {
            componentClass = (Class<?>) componentType;
            if (componentClass == boolean.class) {
                return (T) TypeUtils.cast(list, boolean[].class, parser.getConfig());
            } else if (componentClass == short.class) {
                return (T) TypeUtils.cast(list, short[].class, parser.getConfig());
            } else if (componentClass == int.class) {
                return (T) TypeUtils.cast(list, int[].class, parser.getConfig());
            } else if (componentClass == long.class) {
                return (T) TypeUtils.cast(list, long[].class, parser.getConfig());
            } else if (componentClass == float.class) {
                return (T) TypeUtils.cast(list, float[].class, parser.getConfig());
            } else if (componentClass == double.class) {
                return (T) TypeUtils.cast(list, double[].class, parser.getConfig());
            }

            Object[] array = (Object[]) Array.newInstance(componentClass, list.size());
            list.toArray(array);
            return (T) array;
        } else {
            return (T) list.toArray();
        }

    }

    return (T) parser.parse(fieldName);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:40,代码来源:JavaObjectDeserializer.java

示例14: test_error_5

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_5() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1,null }");
    ArrayList list = new ArrayList();
    parser.config(Feature.AllowISO8601DateFormat, false);

    Exception error = null;
    try {
        parser.parseArray(String.class, list);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:DefaultExtJSONParser_parseArray.java

示例15: test_parseArray

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_parseArray() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[1]");
    parser.config(Feature.AllowArbitraryCommas, false);
    List<String> list = new ArrayList<String>();
    parser.parseArray(String.class, list);
    Assert.assertEquals(1, list.size());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:DefaultExtJSONParserTest_7.java


注:本文中的com.alibaba.fastjson.parser.DefaultJSONParser.parseArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。