Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONReader.readObject()


        JSONReader reader = new JSONReader(new JSONScanner(text));
        reader.startArray();

        int count = 0;
        while (reader.hasNext()) {
            Object item = reader.readObject();
            Assert.assertEquals(JSONArray.class, item.getClass());
            count++;
        }
        Assert.assertEquals(10, count);
View Full Code Here


        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);
View Full Code Here

        JSONReader reader = new JSONReader(new JSONScanner(text));
        reader.startArray();

        int count = 0;
        while (reader.hasNext()) {
            reader.readObject();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endArray();
View Full Code Here

            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));
            reader.startArray();
            while (reader.hasNext()) {
                if (rowBatchBytes == null) {
                    rowBatchBytes = reader.readObject(byte[].class);
                } else if (fileBatchBytes == null) {
                    fileBatchBytes = reader.readObject(byte[].class);
                } else {
                    throw new Exception("archive data json parse failed!");
                }
View Full Code Here

            reader.startArray();
            while (reader.hasNext()) {
                if (rowBatchBytes == null) {
                    rowBatchBytes = reader.readObject(byte[].class);
                } else if (fileBatchBytes == null) {
                    fileBatchBytes = reader.readObject(byte[].class);
                } else {
                    throw new Exception("archive data json parse failed!");
                }

            }
View Full Code Here

        vo.setValue("ABC".getBytes("UTF-8"));
       
        String text = JSON.toJSONString(vo);
       
        JSONReader reader = new JSONReader(new StringReader(text));
        VO vo2 = reader.readObject(VO.class);
        Assert.assertEquals("ABC", new String(vo2.getValue()));
        reader.close();
    }

    public static class VO {
View Full Code Here

        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();
View Full Code Here

    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();
    }
View Full Code Here

public class JSONReaderTest_0 extends TestCase {
  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();
  }
}
View Full Code Here

    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();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.