zoukankan      html  css  js  c++  java
  • json 与字符串相互转换,

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="author" content="智能社 - zhinengshe.com" />
    <meta name="copyright" content="智能社 - zhinengshe.com" />
    <title>智能社 - www.zhinengshe.com</title>
    <script>
    
    var strJson = '{"username":"zns","pwd":123456,"age":18}';//标准格式的json:属性名必须是双引号
    // var strJson = "{'username':'zns','pwd':123456,'age':18}";
    // 1、eval 转为object
    var json = eval("("+strJson+")");//转为json

    //2.JSON.parse(strJSON) 兼容ie8+

    var json = JSON.parse(strJSON);
    console.log(typeof json) //object


    var strJson = JSON.stringify(json);//json转为字符串
    console.log(strJson) //{"username":"zns","pwd":123456,"age":18}
    console.log(typeof strJson) //string
    
    </script>
    </head>
    
    <body>
    
    </body>
    </html>
  • 相关阅读:
    1 3
    linux常用命令
    linux的目录结构
    linux的shell编程
    linux的IP配置
    linux安装
    linux简介
    ubuntu16.04上系统管理服务和配置
    PXE
    RPC框架原理
  • 原文地址:https://www.cnblogs.com/heboliufengjie/p/4517744.html
Copyright © 2011-2022 走看看