json字符串 转换为数组

591 阅读1分钟
  • 使用for in 循环
  • qcshowAnnotation作为json 对象
    item:作为需要的对象存入数组中,可以使用同一的key 或者value 用于渲染。
    for(let key in qcshowAnnotation){ 
     let item = {};
      item.key = qcshowAnnotation[key];
      item.val = res.content.rows[0][key];
        arr.push(item);            
    }
    或者使用需要指定的key 或者value
    for(let key in qcshowAnnotation){ 
     let item = {};
      item[key] = qcshowAnnotation[key];
      arr.push(item);            
    }