当前位置:   article > 正文

nodejs list字符串转json_js list 转json

js list 转json

var liststr="cn=3070091601,ou=BusCatalogGroups,dc=example,dc=com";

// let key='=';

// let jsonstr='';

// jsonstr= liststr.replace(new RegExp(key,'g'),'":"');

// key=',';

// jsonstr= jsonstr.replace(new RegExp(key,'g'),'","');

// jsonstr='{"'+ jsonstr+'"}';

// let json=JSON.parse(jsonstr);

// console.log(jsonstr);

// console.log(json.cn);

 

function strToJson(liststr)

{

let key='=';

let jsonstr='';

jsonstr= liststr.replace(new RegExp(key,'g'),'":"');

key=',';

jsonstr= jsonstr.replace(new RegExp(key,'g'),'","');

jsonstr='{"'+ jsonstr+'"}';

let json=JSON.parse(jsonstr);

return json;

 

}

 

let json=strToJson(liststr);

console.log(json.cn);


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/366857
推荐阅读
相关标签
  

闽ICP备14008679号