我想将我的 JSON 对象从 Javscript 发送到 Struts2 Action。
示例 JSON 对象
{
"lists":["list1","list2","list3","list4","list5"],
"maps": {
"key4":"value4","key3":"value3","key5":"value5","key2":"value2","key1":"value1"
},
"number1":123456789,
"numberarray1":[1,2,3,4,5,6,7,8,9],
"string1":"A",
"stringarray1":["A1","B1"]
}
我的 Jquery Ajax
$.ajax({
type: 'POST',
url: 'json/JSON.action',
data: JSON.stringify(data),
dataType: 'json',
async: false ,
contentType: 'application/json; charset=utf-8',
success: function(){window.alert('Done');}
});
Struts.xml 配置
<action name="JSON" class="com.actions.json.JsonAction" method="getJSON">
<result type="json"/>
</action>
我的行动课
public class JsonAction extends ActionSupport {
private String data;
public String getJSON() {
return ActionSupport.SUCCESS;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
我的问题是如何在操作类中接收 JSON 对象。
注意:POST OF JSON 对象是成功的.. 我只是不知道如何通过 Action Class 接收它.. 请帮助谢谢