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);
时间: 2024-11-15 06:02:38