标签:
private static final JsonFactory factory = new JsonFactory(); StringWriter jsonOut = new StringWriter(1000); JsonGenerator generator = factory.createGenerator(jsonOut); generator .writeStartObject(); generator.writeStringField("article","交易提醒"); generator.writeStringField("url",url); write ObjectField("Name","张三","#000000",generator); generator.writeEndObject(); generator.close(); json = jsonOut.toString();
private static void writeObjectField(String fieldName,String value, String color, JsonGenerator generator) throws IOException{ generator.writeObjectFieldStart(fieldName); generator.writeStringField("value",value); generator.writeStringField("color",color); generator.writeEndObject(); }
使用jackson进行数据的封装非常方便~
标签:
原文地址:http://www.cnblogs.com/yangsy0915/p/5417807.html