我正在向 Struts2 应用程序发布 JSON 请求。json 请求具有值数组。这是 JSON 请求:
{"row":"10","col":"10","data":[{"word":"word1","clue":"clue1"},{"word":"word2","clue":"clue2"}]}
jQuery代码:
jasonRequest = createpuzzle_createjson();
$.ajax({
type: 'POST',
url:'create.action',
dataType: 'json',
data: jasonRequest,
success: function(data){
console.log(stringify(data));
}
});
动作类:
public class GenerateCWAction extends ActionSupport{
private String row;
private String col;
private WCMap[] data;
public String getRow() {
return row;
}
public void setRow(String row) {
this.row = row;
}
public String getCol() {
return col;
}
public void setCol(String col) {
this.col = col;
}
public WCMap[] getData() {
return data;
}
public void setData(WCMap[] data) {
this.data = data;
}
public String execute() {
System.out.println("getRow:" + getRow());
System.out.println("getCol:" + getCol());
System.out.println("getData:" + getData());
return SUCCESS;
}
}
WCMap 类:
public class WCMap {
private String word;
private String clue;
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
public String getClue() {
return clue;
}
public void setClue(String clue) {
this.clue = clue;
}
输出:
getRow:10
getCol:10
getData:null
我想检索数组数据
"数据":[{"word":"word1","clue":"clue1"},{"word":"word2","clue":"clue2"}]
另外,我尝试将数组更改为如下列表;我仍然得到 getData:null
private WCMap[] data;
至
private List<WCMap> data;
你能帮我解决这个问题吗?