codecamp

Fastjson writeJSONString

Fastjson writeJSONString方法

Fastjson 在1.2.11版本中,JSON类新增对OutputStream/Writer直接支持。

package com.alibaba.fastjson;

public abstract class JSON {
   public static final int writeJSONString(OutputStream os, /
                                             Object object, /
                                             SerializerFeature... features) throws IOException;

    public static final int writeJSONString(OutputStream os, /
                                             Charset charset, //  
                                             Object object, // 
                                             SerializerFeature... features) throws IOException;

   public static final int writeJSONString(Writer os, // 
                                             Object object, // 
                                             SerializerFeature... features) throws IOException;
}

Sample

import com.alibaba.fastjson;
import java.nio.charset.Charset;
class Model {
    public int value;
}

Model model = new Model();
model.value = 1001;

OutputStream os = ...;
JSON.writeJSONString(os, model);
JSON.writeJSONString(os, Charset.from("GB18030"), model);

Writer writer = ...;
JSON.writeJSONString(os, model);
Fastjson toJSONString
Fastjson parseObject
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }