1. 程式人生 > >json 遍歷

json 遍歷

  let aa = []
              let bb=
                {aaa: "460-00-593272-46", bbb: "北客站新建1-L-1", ccc: "西安" }
              let cc=
                { aaa: "460-00-593272-46",bbb: "北客站新建1-TL-1", cc: "西安"}
              aa.push(bb)
              aa.push(cc)
              //json轉為物件
         let obj = JSON.parse(aa )
          let cellName = ''
          //遍歷物件
          for (let idx = 0; idx < obj.length; idx++) {
            if (idx === 0) {
              cellName += obj[idx].bbb
            } else {
              cellName += ' , ' + obj[idx].bbb
            }
          }