mxml 代码:<?xml version="1.0" encoding="utf-8"?>
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import com.adobe.serialization.json.*;
[Bindable]
private var jsonObj:Object
internal function getUser(event:ResultEvent):void{
var re:String=event.result.toString();
jsonObj=JSON.decode(re);
}
]]>
java代码
package mxr.flex;
import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import mxr.flex.model.User;
public class DataSource extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String re=DataSource.getAllUsers();
resp.setCharacterEncoding("utf-8");
resp.getWriter().write(re);
System.out.println("aaaaaaaaaa");
//req.setAttribute("users", re);
}
public static void main(String[] args) {
}
public static String getAllUsers(){
String users="null";
List l=new ArrayList();
for(int i=0;i<15;i++){
User u=new User();
u.setName("user-->"+(i+1));
u.setAddress("中国.北京.海淀.上地"+(i+1)+"号");
u.setAge(18+i);
u.setEmail(i+1+"@digitalchina.com");
l.add(u);
}
JSONArray jsonList = JSONArray.fromObject(l);
users=jsonList.toString();
return users;
}
}