jQuery 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数据

 

posted @ 2013-07-02 14:35  cart55free99  阅读(183)  评论(0编辑  收藏  举报