Search in sources :

Example 31 with JSONReader

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

the class JSONReaderTest_object_int method test_read_1.

public void test_read_1() throws Exception {
    String text = "[{},{},{},{},{} ,{},{},{},{},{}]";
    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 32 with JSONReader

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

the class JSONReaderTest_object_int_unquote method test_read.

public void test_read() throws Exception {
    JSONReader reader = new JSONReader(new StringReader(text));
    reader.startObject();
    int count = 0;
    while (reader.hasNext()) {
        String key = (String) reader.readObject();
        Integer value = reader.readInteger();
        count++;
    }
    Assert.assertEquals(10, count);
    reader.endObject();
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 33 with JSONReader

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

the class JSONReaderTest_object_long method test_read.

public void test_read() throws Exception {
    JSONReader reader = new JSONReader(new StringReader(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();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 34 with JSONReader

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

the class JSONReaderTest_object_long method test_read_1.

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();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) JSONReader(com.alibaba.fastjson.JSONReader)

Example 35 with JSONReader

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

the class JSONReaderTest_object_string method test_read.

public void test_read() throws Exception {
    JSONReader reader = new JSONReader(new StringReader(text));
    reader.startObject();
    int count = 0;
    while (reader.hasNext()) {
        String key = (String) reader.readObject();
        String value = reader.readString();
        count++;
    }
    Assert.assertEquals(10, count);
    reader.endObject();
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

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