Search in sources :

Example 96 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class JSONReader_string method test_array_3.

public void test_array_3() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("[[[\"abc\"]]]"));
    reader.startArray();
    reader.startArray();
    reader.startArray();
    Assert.assertEquals("abc", reader.readString());
    reader.endArray();
    reader.endArray();
    reader.endArray();
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 97 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class JSONReaderTest_0 method test_read.

public void test_read() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{}"));
    reader.config(Feature.AllowArbitraryCommas, true);
    JSONObject object = (JSONObject) reader.readObject();
    Assert.assertNotNull(object);
    reader.close();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 98 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class BooleanFieldTest2 method test_true_reader.

public void test_true_reader() throws Exception {
    String text = "{\"f001\":1001,\"value\":true}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Model model = reader.readObject(Model.class);
    Assert.assertTrue(model.value);
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 99 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class BooleanFieldTest2 method test_false_reader.

public void test_false_reader() throws Exception {
    String text = "{\"f001\":1001,\"value\":false}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Model model = reader.readObject(Model.class);
    Assert.assertFalse(model.value);
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 100 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class IntFieldTest2 method test_model_map.

public void test_model_map() throws Exception {
    String text = "{\"model\":{\"id\":-1001,\"id2\":-1002}}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
    });
    Model model2 = map.get("model");
    Assert.assertEquals(-1001, model2.id);
    Assert.assertEquals(-1002, model2.id2);
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader) Map(java.util.Map)

Aggregations

JSONReader (com.alibaba.fastjson.JSONReader)215 StringReader (java.io.StringReader)195 JSONException (com.alibaba.fastjson.JSONException)83 Map (java.util.Map)30 JSONScanner (com.alibaba.fastjson.parser.JSONScanner)11 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 JSONWriter (com.alibaba.fastjson.JSONWriter)3 File (java.io.File)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 JSONArray (com.alibaba.fastjson.JSONArray)2 TypeReference (com.alibaba.fastjson.TypeReference)2 VO (com.alibaba.json.bvt.writeAsArray.WriteAsArray_int_public.VO)2 StringWriter (java.io.StringWriter)2 Field (java.lang.reflect.Field)2 Random (java.util.Random)2 Model (com.alibaba.json.bvt.LongFieldTest_3_stream.Model)1