java - How to parse received json data in action -
i sending json array data jsp action class have included struts2-json-plugin
. want parse receive arraylist
elements. code
in jsp:
$.ajax({ url: "updatenotification", datatype: "json", data: {ids: json.stringify(ids)}, success: function(data) { alert("success " + data.st); } })
in action:
public class test extends actionsupport { arraylist<string> ids = new arraylist<string>(); public arraylist<string> getids() { return ids; } public void setids(arraylist<string> ids) { this.ids = ids; } public string updatenotification() { system.out.println("id " + getids()); (string : getids()) { system.out.println("data " + a); } } }
on running showing data
id [["25","27","28"]] data ["25","27","28"]
how can 1 data 1 array element in action.
edit trying data
ids(0)=25; ids(1)=27; ids(2)=28;
json stringify
method returns array of values in json format ["25","27","28"]
. convert list need remove [
or ]
characters submit csv values. because csv values converted list. try
data: {ids: json.stringify(ids).replace(/[\[\]]/g,'')},
Comments
Post a Comment