我现在想做的是从请求中得到的json数据,该数据有object类型,那么我该在action中如何处理这个数据呢?
传递的数据如下:
var params = {userId: "xxx",user:{username:"111",userId:"222",school:"school"}}
我在action中 提供了 user变量,类型是object:有getxxx(),setxxx()方法:
private String userId;
private Object user;
public String execute() {
System.out.println("JsonPluginAction.execute()"+userId);
map.put("John", "Galt");
return SUCCESS;
}
其中我还定义一个自定义的类,该类有三个属性,分别对应username,userId,school.
那么请问我该如何才能将得到的JSON对象转换成user对象呢?
有人知道的麻烦详细解释下,先谢谢了。
传递的数据如下:
var params = {userId: "xxx",user:{username:"111",userId:"222",school:"school"}}
我在action中 提供了 user变量,类型是object:有getxxx(),setxxx()方法:
private String userId;
private Object user;
public String execute() {
System.out.println("JsonPluginAction.execute()"+userId);
map.put("John", "Galt");
return SUCCESS;
}
其中我还定义一个自定义的类,该类有三个属性,分别对应username,userId,school.
那么请问我该如何才能将得到的JSON对象转换成user对象呢?
有人知道的麻烦详细解释下,先谢谢了。
http://www.blogjava.net/max/archive/2009/11/19/123682.html
里面有这么两个对象net.sf.json.JSONArray; net.sf.json.JSONObject;
用于和java对象之间的装化,具体的可以自己研究,上网找一下吧。
我一般是将jsonString通过统一的模块转成HashMap,如果遇到嵌套Object,那就再新建一个子HashMap放在父HashMap中,最后根据业务模型的不同来根据实际情况从这些HashMap中取值,当有嵌套Object时取到的将是个HashMap。