Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONReader


       
        reader.close();
    }
   
    public void test_array_1() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("[[{\"id\":123}]]"));
       
        reader.startArray();
        List<VO> list = reader.readObject(new TypeReference<List<VO>>() {}.getType());
       
        Assert.assertEquals(123, list.get(0).getId());
       
        reader.endArray();
       
        reader.close();
    }
View Full Code Here


        writer.close();
       
        String text = strWriter.toString();
       
        StringReader strReader = new StringReader(text);
        JSONReader reader = new JSONReader(strReader);
        reader.startArray();
        ;
        while (reader.hasNext()) {
            SectionRequest vo = reader.readObject(SectionRequest.class);
            System.out.println("tag:" + vo.getTag() + "screenHeight:" + vo.getScreenHeight() + "ScreenWidth:"
                               + vo.getScreenWidth());
            Assert.assertEquals(100, vo.getScreenHeight());
            Assert.assertEquals(12, vo.getScreenWidth());
            Assert.assertEquals("11", vo.getTag());

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

import com.alibaba.fastjson.JSONReader;

public class JSONReader_string extends TestCase {

    public void test_array() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("[\"abc\"]"));

        reader.startArray();

        Assert.assertEquals("abc", reader.readString());

        reader.endArray();

        reader.close();
    }
View Full Code Here

        reader.close();
    }
   
    public void test_array_2() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("[[\"abc\"]]"));

        reader.startArray();
        reader.startArray();

        Assert.assertEquals("abc", reader.readString());

        reader.endArray();
        reader.endArray();

        reader.close();
    }
View Full Code Here

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

        try {
            writer.close();
        } catch (IOException e) {
        }

        JSONReader reader = new JSONReader(new StringReader(jsonStr.getBuffer().toString()));
        byte[] oneDates = null;
        byte[] twoDates = null;
        reader.startArray();
        while (reader.hasNext()) {
            if (oneDates == null) {
                oneDates = reader.readObject(byte[].class);
            } else if (twoDates == null) {
                twoDates = reader.readObject(byte[].class);
            } else {
                want.fail("not possible");
            }

        }
        reader.endArray();
        reader.close();
        check(oneDates, one);
        check(twoDates, two);
    }
View Full Code Here

        if (StringUtils.isNotEmpty(key.getKey()) && StringUtils.isNotEmpty(key.getCrc())) {
            decodeFile(archiveFile, key.getKey(), key.getCrc());
        }

        InputStream input = null;
        JSONReader reader = null;
        try {
            input = new BufferedInputStream(new FileInputStream(archiveFile));
            DbBatch dbBatch = new DbBatch();
            byte[] lengthBytes = new byte[4];
            input.read(lengthBytes);
View Full Code Here

        if (StringUtils.isNotEmpty(key.getKey()) && StringUtils.isNotEmpty(key.getCrc())) {
            decodeFile(archiveFile, key.getKey(), key.getCrc());
        }

        InputStream input = null;
        JSONReader reader = null;
        try {
            input = new BufferedInputStream(new FileInputStream(archiveFile));
            DbBatch dbBatch = new DbBatch();
            byte[] lengthBytes = new byte[4];
            input.read(lengthBytes);
View Full Code Here

        writer.endArray();
        writer.close();

        System.out.println(FileUtils.readFileToString(file));

        JSONReader reader = new JSONReader(new FileReader(file));
        reader.startArray();
        reader.readObject();
        reader.endArray();
        reader.close();

    }
View Full Code Here

            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');
            }
            buf.append("\\t");
            JSONReader reader = new JSONReader(new MyReader(buf.toString()));
            reader.readObject();
            reader.close();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
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.