ITPub博客

首页 > > > js拼接对象里面含数组的json数据?

js拼接对象里面含数组的json数据?

作者:founderwzh 时间:2019-11-18 09:56:52 0 删除 编辑

本人新手,对js了解不深,js拼接对象里面含数组json字符串不知道怎么搞了,求大神指导

目标数据格式是后台的兄弟限定死了格式

数组代码

varcrulearr=[]for(varccode ofthis.newDB){if(ccode.id ==this.ipboxid){ crulearr.push('{"rules":[{"field":"ParentID","op":"equal","value":"'+this.ipboxid+'","type":"int"},{"field":"CarbinCode","op":"equal","value":"'+this.cabincodearr+'","type":"string"}],"op":"and"}') }else{ crulearr.push('{"rules":[{"field":"ParentID","op":"equal","value":"'+ccode.id+'","type":"int"},{"field":"CarbinCode","op":"equal","value":"'+ccode.cabincodes+'","type":"string"}],"op":"and"}') } } console.log('row202:'+JSON.stringify(crulearr))

数组数据如下:

拼json数据代码

varrules='{"groups":'+JSON.stringify(crulearr) +',"op":"and"}'this.prule=JSON.parse(rules)console.log('row222:'+JSON.stringify(this.prule) )

获取到的数据如下:

想要实现的数据格式:

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4605/viewspace-3159619/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    159
  • 访问量
    739