jQuery json数据处理

jQuery AJAX与JSON
本文介绍如何使用jQuery的ajax和getJSON函数处理JSON数据。包括不同格式的JSON字符串处理方式及示例代码。

一种是使用jQuery的ajax函数  另一种是使用getJSON函数

使用ajax函数的时候 对于返回值类型dataType 亲自指定为json格式 就无需自己手动处理格式 

            $.ajax({
                url : "me.php",
                type : "POST",
                data: "id=1",
                dataType : "json",
                success : function(data) {
                    //alert(data.address);//后台打印这样的数据  echo "{\"address\": \"CN\",\"status\": \"0\"}";
                    alert(data[0].address);//后台打印这样的数据时 echo "[{\"address\":\"This Is The JSON Data\"}]";//我的json数据时放在一个数组中的
                    /*$(data).each(function(i) {
                        alert(data[i].address);
                    });*/
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error si is  "+errorThrown);
                }
            });

 

        //使用getJSON方法取得JSON数据
            $(function() {
                var url = "FortestJson.php";
                $.getJSON(
                url, function(data) {
                    alert(data.address);
                });
            });

 

http://www.cnblogs.com/xiaowu/archive/2011/09/07/2169283.html  这个帖子里介绍了 含有数组的json字串和不含数组的json字串的处理

http://laputaliya.blog.51cto.com/751941/536858 处理json格式数据

http://developer.51cto.com/art/201007/209635.htm 处理数组式json数据

 

转载于:https://www.cnblogs.com/cart55free99/p/3166937.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值