Search in sources :

Example 16 with JSONWriter

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

the class JSONWriterTest method test_2.

public void test_2() throws Exception {
    StringWriter out = new StringWriter();
    JSONWriter writer = new JSONWriter(out);
    writer.writeStartObject();
    writer.writeKey("id");
    writer.writeValue(33);
    writer.writeKey("name");
    writer.writeValue("jobs");
    writer.writeEndObject();
    writer.flush();
    Assert.assertEquals("{\"id\":33,\"name\":\"jobs\"}", out.toString());
}
Also used : JSONWriter(com.alibaba.fastjson.JSONWriter) StringWriter(java.io.StringWriter)

Example 17 with JSONWriter

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

the class JSONWriterTest method test_1.

public void test_1() throws Exception {
    StringWriter out = new StringWriter();
    JSONWriter writer = new JSONWriter(out);
    writer.writeStartObject();
    writer.writeKey("id");
    writer.writeValue(33);
    writer.writeEndObject();
    writer.flush();
    Assert.assertEquals("{\"id\":33}", out.toString());
}
Also used : JSONWriter(com.alibaba.fastjson.JSONWriter) StringWriter(java.io.StringWriter)

Example 18 with JSONWriter

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

the class JSONWriterTest_0 method test_writer.

public void test_writer() throws Exception {
    StringWriter out = new StringWriter();
    JSONWriter writer = new JSONWriter(out);
    writer.startArray();
    writer.writeObject("1");
    writer.writeObject("2");
    writer.writeObject("3");
    writer.endArray();
    writer.close();
    Assert.assertEquals("[\"1\",\"2\",\"3\"]", out.toString());
}
Also used : JSONWriter(com.alibaba.fastjson.JSONWriter) StringWriter(java.io.StringWriter)

Aggregations

JSONWriter (com.alibaba.fastjson.JSONWriter)18 StringWriter (java.io.StringWriter)17 JSONReader (com.alibaba.fastjson.JSONReader)3 ArrayList (java.util.ArrayList)3 StringReader (java.io.StringReader)2 List (java.util.List)2 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1