本文整理汇总了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;未经允许,请勿转载。 |
请发表评论