日期:2014-05-17 浏览次数:20681 次
var json={
"type":"class",
"text": "root",
"children": [
{
"type":"class",
"text": "children1",
"children": [
{
"type":"class",
"text": "children1_1",
"children": [
{
"type":"value",
"text": "children1_1_value1"
},
{
"type":"value",
"text": "children1_1_value2"
}
]
}
]
},
{
"type":"class",
"text": "children2",
"children": [
{
"type":"value",
"text": "children2_value1"
},
{
"type":"value",
"text": "children2_value2"
}
]
}
]
};
var xml="<root><class value='root'>";
xml += toxml(json['children']);
xml += "</class></root>";
function toxml(json){
var xml_str="";
for(i=0;i<json.length;i++){
if(json[i]["type"]=="class"){