87,909
社区成员
发帖
与我相关
我的任务
分享
var arr = new Array();
arr.type = "common";
arr.address = "china";
var arr1 = new Array();
arr1.type = "common";
arr1.content = "hello,我来自金星";
arr.content = arr1;
var json = [
{a:[{a:1,b:2},
{c:3,d:4}]},
{b:[{a:1,b:2},
{c:3,d:4}]},
{c:[{a:1,b:2},
{c:3,d:4}]},
]
function serialize(o)
{
var result = "";
var tempResult = [];
if(o instanceof Array){
for(var i = 0 ; i < o.length ; i ++)
{
tempResult.push(serialize(o[i]));
}
result = '['+tempResult.join(',')+']';
}
else
{
for(var key in o)
{
if(o[key] instanceof Array) tempResult.push(key+":"+serialize(o[key]));
else tempResult.push(key+":"+o[key]);
}
result = '{'+tempResult.join(',')+'}'
}
return result;
}
alert(serialize(json))