<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JSONTOSTRING DEMO</title>
<script type="text/javascript">
JsonObjectToString=function(o) {
var arr=[];
var fmt = function(s) {
if (typeof s == 'object' && s != null ) return JsonObjectToString(s);
return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
};
if(o instanceof Array){
for (var i in o){
arr.push(fmt(o[i]));
}
return '[' + arr.join(',') + ']';
}
else{
for (var i in o){
arr.push("'" + i + "':" + fmt(o[i]));
}
return '{' + arr.join(',') + '}';
}
};
var json={'vo':{
'id':'20111215103830468760242fbbbc1441299434f4590de40bacc786cf7f96849fb91f3d1aedb4b7053',
'code':'OS2011121500000098',
'corpId':'10000',
'corpName':'中国黄金珠宝有限公司',
'coutomerCode':'10000',
'coutomerName':'10000Cut',
'description':'',
'linkName':'100Name',
'linkNan':'100',
'linkPhone':'010-00000001'
},
'ls':[{
'customerId':'ZS_TEST_0001',
'simpleName':'河南外协厂',
'pickupId':'SUP001',
'pickupName':'章安1',
'idNum':'6100001980101010101',
'outBounderId':'ww1010',
'outBounderName':'西山招商银行',
'fax':'010-10101010',
'rawId':'1000',
'rawName':'9999',
'weight':'592.1133'
},
{'customerId':'10030',
'simpleName':'河南供应商',
'pickupId':null,
'pickupName':'',
'idNum':'',
'outBounderId':'ww1010',
'outBounderName':'西山招商银行',
'fax':'010-10101010',
'rawId':'1000',
'rawName':'9999',
'weight':'7743.5433'
},
{'customerId':'ZS_TEST_0002',
'simpleName':'西安外协厂',
'pickupId':'sup003',
'pickupName':'王五3',
'idNum':'6100001980101010103',
'outBounderId':'ww1010',
'outBounderName':'西山招商银行',
'fax':'010-10101010',
'rawId':'1000',
'rawName':'9999',
'weight':'66.6856'
}]
};
alert(JsonObjectToString(json));
</script>
</head>
<body>
</body>
</html>
JsonObjectToString javascript
最新推荐文章于 2023-10-26 19:59:46 发布