标签:style blog io color ar for sp div on
1 JSON.stringify 2 var o={"a":1,"b":2,"c":"cc","d":{"aaa":1,"bbb":"2"}}; 3 function o2s(o){ 4 var s=[‘{‘]; 5 for(var k in o){ 6 s.push(‘"‘+k+‘":‘); 7 if(typeof o[k] ==‘number‘){ 8 s.push(o[k]); 9 }else if(typeof o[k]==‘object‘){ 10 s.push(o2s(o[k])); 11 }else{ 12 s.push(‘"‘+o[k]+‘"‘); 13 } 14 s.push(‘,‘); 15 } 16 s.pop(); 17 s.push(‘}‘); 18 return s.join(‘‘); 19 } 20 var s=o2s(o); 21 console.log(JSON.parse(s)); 22 alert(o);
标签:style blog io color ar for sp div on
原文地址:http://www.cnblogs.com/rocky2/p/4078068.html