function toXml(obj) {
var xml = {
value:""
};
xml.value += "<?xml version=\"1.0\" encoding='UTF-8'?>"
iterate(obj, xml);
return xml.value;
}
function iterate(obj, xml){
for (let key in obj) {
let value = obj[key]
xml.value += `<${key}>`
if(Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
xml.value += "<item>"
iterate(value[i], xml)
xml.value += "</item>"
}
}else if(value instanceof Object) {
iterate(value, xml)
}else {
xml.value += value
}
xml.value += `</${key}>`
}
}
javascript json转xml
最新推荐文章于 2024-08-22 09:51:44 发布