사용 Lib : JSON-LIB.jar
해당 URL : http://json-lib.sourceforge.net
필수 사항
jakarta commons-lang 2.5
jakarta commons-beanutils 1.8.0
jakarta commons-collections 3.2.1
jakarta commons-logging 1.1.1
ezmorph 1.0.6 - http://ezmorph.sourceforge.net/
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
public class JsonHelper {
public void printJsonObject(HttpServletResponse res, String name, Object obj) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(name, obj);
StringBuffer sb = new StringBuffer();
try {
sb.append(jsonObject.toString());
res.setContentType("text/html");
res.setCharacterEncoding("UTF-8");
PrintWriter out = res.getWriter();
out.print(sb.toString());
out.flush();
out.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
'JAVA' 카테고리의 다른 글
PNG 이미지 배경 투명하게 처리 (0) | 2020.02.03 |
---|---|
[JAVA] LIST형 Remove 하기 (1) | 2019.04.16 |
[JAVA] URLConnection HTTPS 처리 (1) | 2019.03.14 |
[JAVA] 자동리소스 닫기 (2) | 2018.08.02 |