js对象和json对象的转化及其他

js对象转json数据:  JOSN.stringify();json数据转js对象:  JSON.parse();

 <script>
   var  obj = {
         a :  'hello' ,
         b :  'world' ,
         c :  'john'
     };
     var  json = JSON.stringify(obj);
     console.log(json);
     console.log( typeof  json);
 
     console.log( '--------------------------' );
 
     var  obj2 = JSON.parse(json);
     console.log(obj2);
     console.log( typeof  obj2);
</script>


{“a":"hello","b":"world","c":"john"}   string   

--------------------------      {a:"hello",b:"world",c:"john"}     object


猜你喜欢

转载自blog.csdn.net/xiaofanren1111/article/details/79779413