js 二维数组转Json数组 再转json对象数组

function jsonParam(data){  //data是一个二维数组
    var tableColumns = data[0]
    var datajson = {}
    var jsonresult = []
    for (var i = 0; i < data.length; i++) {
      for (var j = 0; j < tableColumns.length; j++) {
        datajson.indexArgs = data[i][0]
        datajson.templateArgs = data[i][1]
        datajson.rate = data[i][2]
        datajson.demandId = data[i][3]
      }
      jsonresult.push(datajson)
      datajson = {}
    }
    console.log(JSON.stringify(jsonresult))
    console.log(jsonresult)//json数组
    return JSON.stringify(jsonresult);
}

结果:[{"indexArgs":"Angle8.0MHZ","templateArgs":"parameter1:8000.0HZ","rate":"1000","demandId":"224055680142882482"}]

你可能感兴趣的:(Js)