Json编码/解码问题

时间:2013-11-22 15:11:23

标签: javascript php ajax json

我在PHP中有这个功能

json_encode(unserialize($response)));

我得到了这个

{"photosets":{"cancreate":1,"page":1,"pages":1,"perpage":2,"total":2,"photoset":[{"id":"7212806405","primary":"1099675","secret":"bdef35451","server":"7384","farm":8,"photos":3,"videos":"0","title":{"_content":"Seo"},"description":{"_content":""},"needs_interstitial":0,"visibility_can_see_set":1,"count_views":"0","count_comments":"0","can_comment":1,"date_create":"1385114442","date_update":"13855"},{"id":"721593276","primary":"10991539336","secret":"a94a094acf","server":"7335","farm":8,"photos":2,"videos":"0","title":{"_content":"Benzina"},"description":{"_content":""},"needs_interstitial":0,"visibility_can_see_set":1,"count_views":"0","count_comments":"0","can_comment":1,"date_create":"1385113740","date_update":"1385141"}]},"stat":"ok"}

在页面中我记得这个javascript代码

$(function () {
        'use strict';
        $.ajax({
            url         : location.protocol + '//' + location.host + '/gallery_photolist.js',
            data        :   {
                                type : 'gallery'
                            },
            dataType    : 'json'
        }).done(function (result) {
            console.log('ok');

但它不会在控制台中记录任何内容。实际上在Firebug中我看到我的页面正确调用了javascript(我可以在选项卡中看到编码的json)但我认为我的脚本无法正确解析Json(我没有标题为“JSON”的标签)。

感谢您的帮助。

编辑:这是一个firebug窗口:

enter image description here

1 个答案:

答案 0 :(得分:1)

您的PHP脚本在发送之前转发JSON,因此您的“响应”选项卡显示转义字符的原因。这就是你问题的原因。