将js中的 array 传输到后端

前端JS代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

var conditons = [];

var test1 = new Object();

test1.name="1";

test1.id="2";

var test2 = new Object();

test2.name="1";

test2.id="2";

conditons.push(test1);

conditons.push(test2);

$(function(){

  $.ajax({

    async:"false",

    type:'post',

    url:'链接',

    data:{name:"123",conditions:JSON.stringify(conditons)},

    dataType : 'json',

    success:function(data){

      console.log(data);

    },

    error: function (XMLHttpRequest, textStatus, errorThrown){

      alert("error");

    }

  });

});

重点注意:将对象数组转为JSON形式的字符串:JSON.stringify

后端获取:

1

2

String conditions = request.getParameter("conditions");

JSONArray conditionList = JSONArray.fromObject(conditions);

   JSONArray outListarray = JSONArray.fromObject(outListstr);
              JSONArray inListarray = JSONArray.fromObject(inListstr);
               List inList = JSONArray.toList(inListarray);
               List outList = JSONArray.toList(outListarray); 

java 后端接收

  JSONArray outListarray = JSONArray.fromObject(outListstr);
		       JSONArray inListarray = JSONArray.fromObject(inListstr);
		       ArrayList inList = (ArrayList) JSONArray.toList(inListarray);
		       ArrayList outList = (ArrayList) JSONArray.toList(outListarray);

js接收后台java 中List  转换为array()

    if(customerChannelFlag) {
                            waf.doPost({
                                action: "targetterminal",
                                async: false,
                                data: {
                                    _method: "entryChange",
                                    cellnames: "SelectcustomerChannelFlag",
                                    customerChannelFlag: customerChannelFlag,
                                    customerId: customer.id,
                                    materialId: material.id,
                                    billID:_self.getCurrentModel().id,
                                    row:rowText,
                                    key:cellname,
                                    adminOrgID: waf("#basedataDept").wafPromptBox("getValue")==null?"": waf("#basedataDept").wafPromptBox("getValue").id,
                                    outList : JSON.stringify(outList),//输出参数
                                    inList : JSON.stringify(inList)   // 输入参数 
                                },
                                success: function (data) {
                                    console.log("判断目标终端库外,提交状态下,不同地区下存在相同目标终端+产品申请---------------");
                                    console.log(data);
                                    var  flag = data.flag;
                                    var  org = data.org;
                                    var  person = data.person;
                                    inList=eval(data.inList);
                                    outList=eval(data.outList);
                                    customerChannelFlag:data.customerChannelFlag;
                                    if(flag=="false"){
                                        _self.showWarning("checkRepeat","校验提醒","您添加的数据【"
										+ customer.name.l2 + "/"
										+ material.name.l2
										+ "】已被其他区域定义过:【"
										+ org.name.l2
										+ "/" + person.name.l2
										+ "】" );
                                    }
                                }
                            }); 
                        }

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值