<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@page import="net.sf.json.JSONObject"%><%@page import="net.sf.json.JSONArray"%><%
List users=new ArrayList<com.guagua.vas.test.UserVO>();
com.test.UserVO u1=new com.test.UserVO();
u1.setNickname("zhangsan");
u1.setScore(100);
u1.setUid(1001);
com.test.UserVO u2=new com.test.UserVO();
u2.setNickname("lisi");
u2.setScore(200);
u2.setUid(1002);
com.test.UserVO u3=new com.test.UserVO();
u3.setNickname("wangwu");
u3.setScore(300);
u3.setUid(1003);
users.add(u1);
users.add(u2);
users.add(u3);
JSONArray array = JSONArray.fromObject(users);
%><%= array.toString()%>
package com.test;
public class UserVO {
private int uid;
private String nickname;
private int score;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
json包版本:json-lib-2.4-jdk15.jar
返回数据:
[{"nickname":"zhangsan","score":100,"uid":1001},{"nickname":"lisi","score":200,"uid":1002},{"nickname":"wangwu","score":300,"uid":1003}]