• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JSONScanner类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.alibaba.fastjson.parser.JSONScanner的典型用法代码示例。如果您正苦于以下问题:Java JSONScanner类的具体用法?Java JSONScanner怎么用?Java JSONScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSONScanner类属于com.alibaba.fastjson.parser包,在下文中一共展示了JSONScanner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: test_string3

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_string3() throws Exception {
    StringBuilder buf = new StringBuilder();

    buf.append('"');
    for (int i = 0; i < 200; ++i) {
        buf.append("abcdefghijklmn012345689ABCDEFG");
    }
    buf.append('"');

    String text = buf.toString();

    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.nextToken();

    Assert.assertEquals(0, lexer.pos());

    lexer.stringVal();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:LexerTest.java


示例2: test_string2

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_string2() throws Exception {
    StringBuilder buf = new StringBuilder();

    buf.append('\'');
    for (int i = 0; i < 200; ++i) {
        buf.append("\\\\\\/\\b\\f\\n\\r\\t\\u" + Integer.toHexString('中'));
    }
    buf.append('\'');

    String text = buf.toString();

    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.config(Feature.AllowSingleQuotes, true);
    lexer.nextToken();

    Assert.assertEquals(0, lexer.pos());

    String stringVal = lexer.stringVal();

    // Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
    // JSON.toJSONString(stringVal));

    JSON.toJSONString(stringVal);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:JSONScannerTest_singQuoteString.java


示例3: test_read_1

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_read_1() throws Exception {
    JSONReader reader = new JSONReader(new JSONScanner(text));

    reader.startObject();

    int count = 0;
    while (reader.hasNext()) {
        String key = (String) reader.readObject();
        Long value = reader.readLong();
        count++;
    }
    Assert.assertEquals(10, count);

    reader.endObject();
    reader.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONReaderTest_object_long.java


示例4: test_string4

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_string4() throws Exception {
    StringBuilder buf = new StringBuilder();

    buf.append('\'');
    for (int i = 0; i < 200; ++i) {
        buf.append("\\tabcdefghijklmn012345689ABCDEFG");
    }
    buf.append('\'');

    String text = buf.toString();

    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.config(Feature.AllowSingleQuotes, true);
    lexer.nextToken();

    Assert.assertEquals(0, lexer.pos());

    String stringVal = lexer.stringVal();

    // Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
    // JSON.toJSONString(stringVal));

    JSON.toJSONString(stringVal);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:JSONScannerTest_singQuoteString.java


示例5: test_read_3

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_read_3() throws Exception {
    JSONReader reader = new JSONReader(new JSONScanner(text));
    reader.startArray();

    
    
    Assert.assertTrue(reader.hasNext());
    reader.startObject();
    reader.endObject();
    
    Assert.assertTrue(reader.hasNext());
    reader.startObject();
    reader.endObject();
    
    int count = 2;
    
    while (reader.hasNext()) {
        reader.startObject();
        reader.endObject();
        count++;
    }
    Assert.assertEquals(10, count);

    reader.endArray();
    reader.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:JSONReaderTest_array_object.java


示例6: castToSqlDate

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public static java.sql.Date castToSqlDate(Object value){
    if(value == null){
        return null;
    }
    if(value instanceof java.sql.Date){
        return (java.sql.Date) value;
    }
    if(value instanceof java.util.Date){
        return new java.sql.Date(((java.util.Date) value).getTime());
    }
    if(value instanceof Calendar){
        return new java.sql.Date(((Calendar) value).getTimeInMillis());
    }
    long longValue = 0;
    if(value instanceof Number){
        longValue = ((Number) value).longValue();
    }
    if(value instanceof String){
        String strVal = (String) value;
        if(strVal.length() == 0 //
                || "null".equals(strVal) //
                || "NULL".equals(strVal)){
            return null;
        }
        if(isNumber(strVal)){
            longValue = Long.parseLong(strVal);
        } else{
            JSONScanner scanner = new JSONScanner(strVal);
            if(scanner.scanISO8601DateIfMatch(false)){
                longValue = scanner.getCalendar().getTime().getTime();
            } else{
                throw new JSONException("can not cast to Timestamp, value : " + strVal);
            }
        }
    }
    if(longValue <= 0){
        throw new JSONException("can not cast to Date, value : " + value); // TODO 忽略 1970-01-01 之前的时间处理?
    }
    return new java.sql.Date(longValue);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:TypeUtils.java


示例7: test_0

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_0() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("name".equals(symbol));
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例8: test_1

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_1() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick name".equals(symbol));
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例9: test_5

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_5() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\bname\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \bname" == symbol);
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例10: test_6

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_6() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\f name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \f name" == symbol);
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例11: test_float

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_float() throws Exception {
    String text = "123456789.0123";
    JSONScanner lexer = new JSONScanner(text);
    lexer.nextToken();
    BigDecimal decimalValue = lexer.decimalValue();
    Assert.assertEquals(new BigDecimal("123456789.0123"), decimalValue);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:LexerTest.java


示例12: test_10

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_10() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\t name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick \t name" == symbol);
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例13: test_11

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_11() throws Exception {
    SymbolTable symbolTable = new SymbolTable(512);

    JSONScanner lexer = new JSONScanner("\"nick \\u4e2d name\"");
    String symbol = lexer.scanSymbol(symbolTable, '"');
    Assert.assertTrue("nick 中 name" == symbol);
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONScannerTest_symbol.java


示例14: test_for_issue_b

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_for_issue_b() throws Exception {
    JSONScanner lexer = new JSONScanner("-10B");
    lexer.scanNumber();
    Assert.assertEquals(Byte.class, lexer.integerValue().getClass());
    Assert.assertEquals(-10, lexer.integerValue().byteValue());
    lexer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:Issue119.java


示例15: test_error

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_error() throws Exception {
    JSONException error = null;
    try {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick \\a name\"");
        lexer.scanSymbol(symbolTable, '"');
        lexer.close();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONScannerTest_symbol.java


示例16: test_error_2

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_error_2() throws Exception {
    JSONException error = null;
    try {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"name");
        lexer.scanSymbol(symbolTable, '"');
        lexer.close();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONScannerTest_symbol.java


示例17: test_error

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_error() throws Exception {
    Exception error = null;
    try {
        JSONScanner lexer = new JSONScanner("'k");
        lexer.config(Feature.AllowSingleQuotes, true);
        lexer.nextToken();
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:JSONScannerTest_singQuoteString.java


示例18: test_error_1

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_error_1() {
    Exception error = null;
    try {
        String text = Integer.MAX_VALUE + "1234";
        JSONScanner lexer = new JSONScanner(text);
        lexer.scanNumber();
        lexer.intValue();
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JSONScannerTest_int.java


示例19: test_error1

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_error1() throws Exception {
    Exception error = null;
    try {
        JSONScanner lexer = new JSONScanner("\"\\k\"");
        lexer.nextToken();
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:LexerTest.java


示例20: test_scan_true_1

import com.alibaba.fastjson.parser.JSONScanner; //导入依赖的package包/类
public void test_scan_true_1() throws Exception {
    JSONException error = null;
    try {
        JSONScanner lexer = new JSONScanner("frue");
        lexer.scanTrue();
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JSONScannerTest_true.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodeHeartbeatRequestPBImpl类代码示例发布时间:2022-05-22
下一篇:
Java VirtualFile类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap