js拼接json对象_JS字符串拼接JSON问题
第⼀种种拼接json的key会过滤双引号
var arr = "sequence" + ":" + "[";
let arrEnd = "]";
for(let i=0;i
js获取json的key和valuearr += "{" +"sequence" + ":" + [1,2,3][i] + "," + "process" + "[" + [[1,2,3],[2,4],[5,4]][i]+"]"+"}"+",";
}
let arrs = '{' + arr.substring(0,arr.length-1)+arrEnd + '}';
console.log(arrs);//{sequence:[{sequence:1,process[1,2,3]},{sequence:2,process[2,4]},{sequence:3,process[5,4]}]}
第⼆种拼接数组[1,2,3]会被当字符串处理
var arr = "sequence" + ":" + "[";
let arrEnd = "]";
for(let i=0;i
arr += "{ \"sequence\": [1,2,3][i], \"process\": [[[1,2,3],[2,4],[5,4]][i]]}"+",";
}
let arrs = JSON.stringify('{' + arr.substring(0,arr.length-1)+arrEnd + '}');
console.log(JSON.parse(arrs)); /*{sequence:[{ "sequence": [1,2,3][i], "process": [[[1,2,3],[2,4],[5,4]][i]]},{ "sequence": [1,2,3] [i], "process": [[[1,2,3],[2,4],[5,4]][i]]},{ "sequence": [1,2,3][i], "process": [[[1,2,3],[2,4],[5,4]][i]]}]}*/
求⼀种拼接完能和json格式⼀样的⽅法,然后要能取的到值

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。