1、将字符串转为json对象:JSON.parse();

2、json对象转字符串:JSON.stringify();

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>创建json字符串对象</title>
    </head>
    <body>
    </body>
    <script src="js/jquery-2.1.0.js"></script>
    <script type="text/javascript">
        $(function(){
            // 字符串
            var str='{"name":"小明","age":18}';
            
            // 将字符串转为json对象
            var jsonstr=JSON.parse(str);
            console.log(typeof(jsonstr))
            
            // json对象转字符串
            var string=JSON.stringify(jsonstr);
            console.log(typeof(string))
        });
    </script>
</html>
json字符串对象

 


 

相关文章:

  • 2022-02-07
  • 2021-10-15
  • 2022-12-23
  • 2022-02-07
  • 2021-12-03
  • 2022-02-26
  • 2021-11-21
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-02-21
  • 2022-01-18
相关资源
相似解决方案