function paseToObj(str){
let re = /(\S*?) ?: ?\'(\S*?)\'/g;
let iter = str.matchAll(re);
let res = {};
let i = iter.next();
while(!i['done']){
res[i['value'][1]] = i['value'][2];
i = iter.next();
}
return res;
}
let str = `[{ name : '学生:' , code: '[12345678]林XX' }]`;
console.log(paseToObj(str));
用正则简单写了个转对象的例子,你可以试试
function paseToObj(str){ let re = /(\S*?) ?: ?\'(\S*?)\'/g; let iter = str.matchAll(re); let res = {}; let i = iter.next(); while(!i['done']){ res[i['value'][1]] = i['value'][2]; i = iter.next(); } return res; } let str = `[{ name : '学生:' , code: '[12345678]林XX' }]`; console.log(paseToObj(str));
让后端给你转规范来