jsp生成json数据

http://code.google.com/p/json-simple上有个jar包,导入放到工程中的\WEB-INF\lib中

新建jsp页面

<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%
    JSONObject obj=new JSONObject();
    obj.put("name","foo");
    obj.put("num",new Integer(100));
    obj.put("balance",new Double(1000.21));
    obj.put("is_vip",new Boolean(true));
    obj.put("nickname",null);
    out.print(obj);
    out.flush();
%>

页面上就有json形式的数据了

posted @ 2012-08-15 13:59  Marble  阅读(11151)  评论(0编辑  收藏  举报