js 数组 在java中怎么读取 急啊!
5个回答
展开全部
javascript是前台的脚本语言、java不能直接读取、你可以将js的数组以一个特殊符号分割组成一个字符串传到后台在用java的split方法转换成数组!
比如:
js code: var arr = {'a','b','c'}; => var ss = “a&b&c”;
java code:String ss = "a&b&c";String[] arr = ss.split('&');
比如:
js code: var arr = {'a','b','c'}; => var ss = “a&b&c”;
java code:String ss = "a&b&c";String[] arr = ss.split('&');
追问
在JAVA中我取出来的是这种,我不知道怎么把它转换成对象。[{plbm:reference:c0-e15, pwmc:reference:c0-e16, bzjg:reference:c0-e17, orgid:reference:c0-e18, sl:reference:c0-e19, zje:reference:c0-e20}, {plbm:reference:c0-e22, pwmc:reference:c0-e23, bzjg:reference:c0-e24, orgid:reference:c0-e25, sl:reference:c0-e26, zje:reference:c0-e27}]
追答
你js里的数组里面放的是什么数据?格式是怎么样的?
展开全部
你可以把接收的字符串“[{plbm:reference:c0-e15, pwmc:reference:c0-e16, bzjg:reference:c0-e17, orgid:reference:c0-e18, sl:reference:c0-e19, zje:reference:c0-e20}, {plbm:reference:c0-e22, pwmc:reference:c0-e23, bzjg:reference:c0-e24, orgid:reference:c0-e25, sl:reference:c0-e26, zje:reference:c0-e27}]”转换成二维数组,然后操作这个二维数组就可以了。
String s = "[{plbm:reference:c0-e15, pwmc:reference:c0-e16, bzjg:reference:c0-e17, orgid:reference:c0-e18, sl:reference:c0-e19, zje:reference:c0-e20}, {plbm:reference:c0-e22, pwmc:reference:c0-e23, bzjg:reference:c0-e24, orgid:reference:c0-e25, sl:reference:c0-e26, zje:reference:c0-e27}]";
String [] arr = s.split("}");
String [][] arr2 = new String[arr.length - 1][arr[0].split(",").length];
for (int i = 0; i < arr.length - 1; i ++) {
String[] s1 = arr[i].split(",");
for (int j = 0; j < s1.length; j ++) {
if (i > 0) {
if (j > 0) {
if (j == 1) {
arr2[i][j - 1] = s1[j].substring(2);
} else {
arr2[i][j - 1] = s1[j];
}
}
} else {
if (j == 0) {
arr2[i][j] = s1[j].substring(2);
} else {
arr2[i][j] = s1[j];
}
}
}
}
String s = "[{plbm:reference:c0-e15, pwmc:reference:c0-e16, bzjg:reference:c0-e17, orgid:reference:c0-e18, sl:reference:c0-e19, zje:reference:c0-e20}, {plbm:reference:c0-e22, pwmc:reference:c0-e23, bzjg:reference:c0-e24, orgid:reference:c0-e25, sl:reference:c0-e26, zje:reference:c0-e27}]";
String [] arr = s.split("}");
String [][] arr2 = new String[arr.length - 1][arr[0].split(",").length];
for (int i = 0; i < arr.length - 1; i ++) {
String[] s1 = arr[i].split(",");
for (int j = 0; j < s1.length; j ++) {
if (i > 0) {
if (j > 0) {
if (j == 1) {
arr2[i][j - 1] = s1[j].substring(2);
} else {
arr2[i][j - 1] = s1[j];
}
}
} else {
if (j == 0) {
arr2[i][j] = s1[j].substring(2);
} else {
arr2[i][j] = s1[j];
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不固定的也可以用json啊,json只是一种数据的表达形式,跟内容无关,具体对内容的操作都是你JAVA代码完成的,js只负责把数据格式化成固定的格式让后台接收而已
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
json,或者字符串处理,当然,你要通过FORM传值也可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getParamValues("array");
如果你里面放的是固定类的话就用json
如果你里面放的是固定类的话就用json
追问
不是固定的呢
追答
你把你需求发下吧,干说没啥感觉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |