首页 > Web开发 > 详细

json字符串对象

时间:2019-08-20 11:58:54      阅读:61      评论:0      收藏:0      [点我收藏+]

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字符串对象

原文:https://www.cnblogs.com/xiaozhou223/p/11382046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!