zoukankan      html  css  js  c++  java
  • JSON的使用

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-1.10.2.js"></script>
        <script type="text/javascript">
    
    
            function ConvertToJSON() {
                var str = '{ "name": "song", "occupation": "character" }';
                var obj = $.parseJSON(str);
                alert(obj.name);
                alert(obj.occupation);
            }
    
            function JSONToString() {
                var str = { "name": "song", "occupation": "character" };
                var jsonstring = JSON.stringify(str);
                alert(jsonstring);
            }
    
    
            function JSONData() {
                //定义一个JSON对象
                var user = {
    
                    "username": "andy",
                    "age": 20,
                    "info": { "tel": "123456", "cellphone": "98765" },
                    "address":
                               [
                                    { "city": "beijing", "postcode": "222333" },
                                    { "city": "newyork", "postcode": "555666" }
                               ]
                }
                //获取JSON对象数据
                alert("Name: " + user.username);
                alert("age:" + user.age);
                alert("Info Object:" + user.info.tel + "---" + user.info.cellphone);
                alert(user.address[0].city + "----" + user.address[0].postcode);
                alert(user.address[1].city + "----" + user.address[1].postcode);
            }
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <input id="Button1" type="button" value="Show JSON Data" onclick="JSONData();" /><br />
                <input id="Button2" type="button" value="Convert String to JSON" onclick="ConvertToJSON();" />
                <input id="Button3" type="button" value="Convert JSON to String" onclick="JSONToString();" />
            </div>
        </form>
    </body>
    </html>
    View Code
  • 相关阅读:
    B1295 [SCOI2009]最长距离 最短路
    B1588 [HNOI2002]营业额统计 set||平衡树
    B1202 [HNOI2005]狡猾的商人 并查集
    B1303 [CQOI2009] 中位数图 数学
    B2002 [Hnoi2010]Bounce 弹飞绵羊 分块
    B1192 [HNOI2006]超级英雄Hero 二分图匹配
    逐个击破
    HAOI2009 毛毛虫
    HNOI/AHOI2018 道路
    NOI2005 瑰丽华尔兹
  • 原文地址:https://www.cnblogs.com/songxia/p/4347693.html
Copyright © 2011-2022 走看看