Search in sources :

Example 31 with JSONReaderScanner

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

the class JSONReaderScannerTest method test_singleQuote.

public void test_singleQuote() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{'name':'张三\\'\\n\\r\\\"'}"));
    JSONObject json = parser.parseObject();
    Assert.assertEquals("张三\'\n\r\"", json.get("name"));
    parser.close();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 32 with JSONReaderScanner

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

the class JSONReaderScannerTest_boolean method test_false.

public void test_false() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":false}"));
    JSONObject json = parser.parseObject();
    Assert.assertEquals(Boolean.FALSE, json.get("name"));
    parser.close();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 33 with JSONReaderScanner

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

the class JSONReaderScannerTest_matchField method test_true.

public void test_true() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"items\":[{}],\"value\":{}}"));
    VO vo = parser.parseObject(VO.class);
    Assert.assertNotNull(vo.getValue());
    Assert.assertNotNull(vo.getItems());
    Assert.assertEquals(1, vo.getItems().size());
    Assert.assertNotNull(vo.getItems().get(0));
    parser.close();
}
Also used : JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 34 with JSONReaderScanner

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

the class JSONReaderScannerTest_negative method test_float.

public void test_float() throws Exception {
    char[] chars = "{\"value\":-3.5F}".toCharArray();
    DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length));
    JSONObject json = parser.parseObject();
    Assert.assertTrue(-3.5F == ((Float) json.get("value")).doubleValue());
    parser.close();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 35 with JSONReaderScanner

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

the class JSONReaderScannerTest_negative method test_double.

public void test_double() throws Exception {
    char[] chars = "{\"value\":-3.5D}".toCharArray();
    DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length));
    JSONObject json = parser.parseObject();
    Assert.assertTrue(-3.5D == ((Double) json.get("value")).doubleValue());
    parser.close();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Aggregations

JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)35 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)34 JSONObject (com.alibaba.fastjson.JSONObject)14 Reader (java.io.Reader)14 StringReader (java.io.StringReader)14 JSONArray (com.alibaba.fastjson.JSONArray)5 BigDecimal (java.math.BigDecimal)3 LinkedHashMap (java.util.LinkedHashMap)1