在java的action里面怎么获取jquery的ajax提交过来的json数据,数据的格式是

[{"sDepartmentId":"006","sCarType":"C","iPlanNumber":"0"},{"sDepartmentId":"006","sCarType":"P","iPlanNumber":"0"},{"sDepartmentId":"006","sCarType":"N","iPlanNumber":"0"},{"sDepartmentId":"006","sCarType":"G","iPlanNumber":"0"},{"sDepartmentId":"006","sCarType":"T","iPlanNumber":"0"},{"sDepartmentId":"007","sCarType":"C","iPlanNumber":"0"},{"sDepartmentId":"007","sCarType":"P","iPlanNumber":"0"},{"sDepartmentId":"007","sCarType":"N","iPlanNumber":"0"},{"sDepartmentId":"007","sCarType":"G","iPlanNumber":"0"},{"sDepartmentId":"007","sCarType":"T","iPlanNumber":"0"},{"sDepartmentId":"004","sCarType":"C","iPlanNumber":"0"},{"sDepartmentId":"004","sCarType":"P","iPlanNumber":"0"},{"sDepartmentId":"004","sCarType":"N","iPlanNumber":"0"},{"sDepartmentId":"004","sCarType":"G","iPlanNumber":"0"},{"sDepartmentId":"004","sCarType":"T","iPlanNumber":"0"},{"sDepartmentId":"005","sCarType":"C","iPlanNumber":"0"},{"sDepartmentId":"005","sCarType":"P","iPlanNumber":"0"},{"sDepartmentId":"005","sCarType":"N","iPlanNumber":"0"},{"sDepartmentId":"005","sCarType":"G","iPlanNumber":"0"},{"sDepartmentId":"005","sCarType":"T","iPlanNumber":"0"}]

这样的,我在后台改怎样会的啊!求高手帮助一下,谢谢!
最新回答
伤疤像㈠朵鲜花

2024-05-12 06:52:58

如果要冲界面上要传到后台的话可以先将json对象转换成js对象(用evalJSON()方法可以转),然后当做参数传回来,action中就用request.getParameter()方法就能拿到了,不过看楼主的格式传过来的对象是一个数组,要拿到具体的值要用下标来那,比如你在action用一个objs去getParament这个传过来的对象的话,要拿到相应的第一行的值要这样:objs[0].sDepartmentId 拿到的值便是第一行的006,自己去试一下!嘿嘿
夏了夏天

2024-05-12 00:08:51

这种数据你编码成字符串后,把整个字符串发post请求,接收到后再用json工具类解析出来。http请求编码数组貌似提交不行。我以前直接干过这事,貌似出问题。
搁浅

2024-05-12 19:35:22

没有唯一标识符吗??你的数据

$.post(
"<%=basePath%>/chg", //url
{newpwd:$("#newpwd2").val()}, //参数
function(data){
$("#sp").html(data); //回调函数

},
"html"
);

String newpwd=request.getParameter("newpwd"); //获得新密码
浅笑未央人自笑

2024-05-12 09:24:14

用Google gson 就可以转了 Gson类有方法fromJson(str)
旭日东山再起

2024-05-12 13:17:00

使用Struts的JSON插件,直接接收JSON数据
追问
能说的在详细些吗,能给我写个列子吗,谢谢!