Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONReader


        reader.endObject();
        reader.close();
    }

    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();
            Object value = reader.readObject();
           
            Assert.assertNotNull(key);
            Assert.assertNotNull(value);
           
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endObject();
        reader.close();
    }
View Full Code Here


        reader.endObject();
        reader.close();
    }

    public void test_read_2() throws Exception {
        JSONReader reader = new JSONReader(new JSONScanner("{{}:{},{}:{}}"));
        reader.startObject();

        Assert.assertTrue(reader.hasNext());
        reader.startObject();
        reader.endObject();

        reader.startObject();
        reader.endObject();

        Assert.assertTrue(reader.hasNext());
        reader.startObject();
        reader.endObject();

        reader.startObject();
        reader.endObject();
       
        Assert.assertFalse(reader.hasNext());

        reader.endObject();

        Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);

        reader.close();
    }
View Full Code Here

    String text = "[[],[],[],[],[], [],[],[],[],[]]";

    public void test_read() throws Exception {

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

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

        reader.endArray();
        reader.close();
    }
View Full Code Here

        reader.endArray();
        reader.close();
    }

    public void test_read_1() throws Exception {
        JSONReader reader = new JSONReader(new JSONScanner(text));
        reader.startArray();

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

        reader.endArray();
        reader.close();
    }
View Full Code Here

    String text = "[[],[],[],[],[], [],[],[],[],[]]";

    public void test_read() throws Exception {

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

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

        reader.endArray();
        reader.close();
    }
View Full Code Here

        reader.endArray();
        reader.close();
    }

    public void test_read_1() throws Exception {
        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);

        reader.endArray();
        reader.close();
    }
View Full Code Here

public class JSONReaderTest_object_int extends TestCase {

    public void test_read() throws Exception {
        String text = "{\"f0\":0,\"f1\":1,\"f2\":2,\"f3\":3,\"f4\":4, " + //
                      "\"f5\":5,\"f6\":6,\"f7\":7,\"f8\":8,\"f9\":9}";
        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();
    }
View Full Code Here

        reader.close();
    }

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

import com.alibaba.fastjson.JSONReader;

public class JSONReader_top extends TestCase {

    public void test_int() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Integer(123), reader.readInteger());

        reader.close();
    }
View Full Code Here

        reader.close();
    }

    public void test_long() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Long(123), reader.readLong());

        reader.close();
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONReader

Copyright © 2018 www.massapicom. 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.