Search in sources :

Example 91 with JSONReader

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

the class JSONReader_map method test_map.

public void test_map() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));
    Map<String, Object> map = new HashMap<String, Object>();
    reader.readObject(map);
    Assert.assertEquals(123, map.get("id"));
    reader.close();
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 92 with JSONReader

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

the class JSONReader_map method test_array.

public void test_array() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("[{\"id\":123}]"));
    reader.startArray();
    Map<String, Object> map = new HashMap<String, Object>();
    reader.readObject(map);
    Assert.assertEquals(123, map.get("id"));
    reader.endArray();
    reader.close();
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 93 with JSONReader

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

the class JSONReader_obj method test_obj.

public void test_obj() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));
    VO vo = new VO();
    reader.readObject(vo);
    Assert.assertEquals(123, vo.getId());
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 94 with JSONReader

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

the class JSONReader_obj_2 method test_array.

public void test_array() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("[{\"id\":123}]"));
    reader.startArray();
    VO vo = reader.readObject(VO.class);
    Assert.assertEquals(123, vo.getId());
    reader.endArray();
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 95 with JSONReader

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

the class JSONReader_obj_3 method test_obj.

public void test_obj() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));
    reader.startObject();
    Assert.assertEquals("id", reader.readString());
    Assert.assertEquals(Integer.valueOf(123), reader.readInteger());
    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