中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何将xml字符串转换为json串?
微信扫码分享
let xml = '<?xml version="1.0" encoding="utf-8"?>' + '<note importance="high" logged="true">' + ' <title>Happy</title>' + ' <todo>Work</todo>' + ' <todo>Play</todo>' + '</note>'; let conv = new convertxml.ConvertXML() let options: convertxml.ConvertOptions = { trim: false, declarationKey: "_declaration", instructionKey: "_instruction", attributesKey: "_attributes", textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype", commentKey: "_comment", parentKey: "_parent", typeKey: "_type", nameKey: "_name", elementsKey: "_elements" } let result = JSON.stringify(conv.convertToJSObject(xml, options)); console.log(result);