原理:先分割中括号,组成数组,将数组中的数据遍历出来,再分割双引号,再组成数组,然后将数组的基数设置为键,偶数设置为值,组成对象,添加到数组中
let info = “[{"license":"X京房权证朝字第1157582号","certificationDate":"2021-01-02","building":"1期1-5号楼"},{"license":"X京房权证朝字第1157583号","building":"2期1-5号楼"}]”
//拆分字符串
let regex = /{([^{]*)}/g;
let currentResult;
let results = [];
let shuzu = []
//分割大括号 组合成数组
while ((currentResult = regex.exec(infos[0].qualifications)) !== null) {
results.push(currentResult[1]);
}
//遍历数组,在分割双引号
for(let i in results){
let regex2 = /"([^"]*)"/g;
let currentResult2;
let results2 = [];
let duixiang={};
while ((currentResult2 = regex2.exec(results[i])) !== null) {
results2.push(currentResult2[1]);
}
// 组合成新的数组
for(let i2=0;i2<results2.length;i2+=2){
let key = results2[i2];
let value = results2[i2+1];
duixiang[key] = value;
}
//添加到对象中
shuzu.push(duixiang);
}