Search in sources :

Example 16 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONReaderTest_array_object method test_read_1.

public void test_read_1() throws Exception {
    JSONReader reader = new JSONReader(new JSONScanner(text));
    reader.startArray();
    int count = 0;
    while (reader.hasNext()) {
        reader.readObject();
        count++;
    }
    Assert.assertEquals(10, count);
    reader.endArray();
    reader.close();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) JSONReader(com.alibaba.fastjson.JSONReader)

Example 17 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_ISO8601 method test_3.

public void test_3() throws Exception {
    JSONScanner lexer = new JSONScanner("2000-2");
    lexer.config(Feature.AllowISO8601DateFormat, true);
    lexer.nextToken();
    Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token());
    lexer.nextToken();
    Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token());
    lexer.nextToken();
    Assert.assertEquals(JSONToken.EOF, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 18 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_ISO8601 method test_2.

public void test_2() throws Exception {
    JSONScanner lexer = new JSONScanner("2000-02-10T00:00:00.000");
    lexer.config(Feature.AllowISO8601DateFormat, true);
    Assert.assertEquals(true, lexer.scanISO8601DateIfMatch());
    Assert.assertEquals(JSONToken.LITERAL_ISO8601_DATE, lexer.token());
    lexer.nextToken();
    Assert.assertEquals(JSONToken.EOF, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 19 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest__nextToken method test_next_1.

public void test_next_1() throws Exception {
    String text = "[";
    JSONScanner lexer = new JSONScanner(text);
    lexer.nextToken(JSONToken.LITERAL_INT);
    Assert.assertEquals(JSONToken.LBRACKET, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 20 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest__nextToken method test_next_7.

public void test_next_7() throws Exception {
    String text = "{";
    JSONScanner lexer = new JSONScanner(text);
    lexer.nextToken(JSONToken.EOF);
    Assert.assertEquals(JSONToken.LBRACE, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Aggregations

JSONScanner (com.alibaba.fastjson.parser.JSONScanner)179 JSONException (com.alibaba.fastjson.JSONException)37 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)15 JSONReader (com.alibaba.fastjson.JSONReader)11 ParseException (java.text.ParseException)5 BigInteger (java.math.BigInteger)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigDecimal (java.math.BigDecimal)1 AccessControlException (java.security.AccessControlException)1 Calendar (java.util.Calendar)1