日期:2014-05-17 浏览次数:20679 次
public class Test3 {
public static void main(String[] args) {
String json = "{'num':11,'org':{'orgId':'orgId','orgName':'orgName'},'biz':" +
"[{'appcode':55,'subscode':'subscode0'},{'appcode':66,'subscode':'subscode1'}]}";
JSONObject jo = JSONObject.fromObject(json);
System.out.println(jo.get("num"));
JSONObject orgJson= jo.getJSONObject("org");
System.out.println(orgJson);
System.out.println(orgJson.get("orgId"));
JSONArray bizJson= jo.getJSONArray("biz");
System.out.println(bizJson.getJSONObject(0).get("appcode"));
}
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
ChatDao cd=new ChatDao();
List<Chat> chatList=new ArrayList<Chat>();
chatList=cd.chatList();
JSONArray json=JSONArray.fromObject(chatList);
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out=resp.getWriter();
out.println(json.toString());
}
<script type="text/javascript">
var xhq;
var input;
//创建XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xhq=new XMLHttpRequest();
}else if(window.ActiveXObject){
try{
xhq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xhq=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
}
}
}
}
//发送数据到服务器<