我的json响应键包含“$”,它给了我未定义的值

时间:2011-10-02 11:54:34

标签: jquery json

我收到了json回复 当我提醒数据时,我看到这些值,但当我提醒数据。$跟踪它给我undefined我也尝试data.tracking但没有希望

function GetVideos(URI, PageSize) {
    alert("in GetVideos: " + URI + PageSize);
    $.ajax({
        type: "GET",
        url: URI,
        async: false,
        dataType: "application/json",
        success: function(data) {
            alert(data.$tracking);
        },
        error: function(err) {
            alert("error" + err.toString());
        }
    });


}

{
    "$tracking": "uuids",
    "$execTime": "0",
    "video": [
        {
            "$publishState": "UpdatePending",
            "$lcid": "1033",
            "$options": "0",
            "$version": "158",
            "$filterFlags": "9103",
            "uuid": {
                "$ref": "3rzh6xt5",
                "$seoMetaData": "\x2fvideo\x2fvenice-beach\x2f",
                "$": "2ec4173b-47ab-4bed-b694-9fd966f5b5b3"
            },
            "providerId": {
                "$": "VeniceBeach_201337"
            },
            "csId": {
                "$": "Turnhere"
            },
            "source": {
                "$friendlyName": "TurnHere",
                "$": "TurnHere"
            },
            "pageGroup": {
                "$": "MSVLIF"
            },
            "title": {
                "$": "Venice Beach"
            },
            "description": {
                "$": "Dude. Catch some hippie vibes strolling down Ocean Front Walk-- smoke a hooka, exercise your free speech and let the eclectic street performers inspire your inner muse."
            },
            "durationSecs": {
                "$": 269
            },
            "startDate": {
                "$": "2007-09-13T00\x3a00\x3a00Z"
            },
            "activeEndDate": {
                "$": "2013-09-14T00\x3a00\x3a00Z"
            },
            "searchableEndDate": {
                "$": "2013-09-14T00\x3a00\x3a00Z"
            },
            "archiveEndDate": {
                "$": "2099-12-31T00\x3a00\x3a00Z"
            },
            "tags": {
                "tag": [
                    {
                        "$market": "us",
                        "$namespace": "Duration",
                        "$source": "2",
                        "$premium": "1",
                        "$": "short"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Genre",
                        "$source": "5",
                        "$premium": "1",
                        "$": "entertainment"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top",
                        "$source": "5",
                        "$premium": "0",
                        "$": "MSNVideo_Top_Lifestyles"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top_Cat",
                        "$source": "5",
                        "$premium": "0",
                        "$": "Most Watched Life"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top_Cat",
                        "$source": "2",
                        "$premium": "0",
                        "$": "Source_TurnHere"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top_Cat",
                        "$source": "5",
                        "$premium": "0",
                        "$": "Travel_General"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "4",
                        "$premium": "0",
                        "$": "Venice"
                    },
                    {
                        "$market": "us",
                        "$namespace": "VC_Source",
                        "$source": "2",
                        "$premium": "1",
                        "$": "Turnhere\x3aTurnHere"
                    },
                    {
                        "$market": "us",
                        "$namespace": "VC_Supplier",
                        "$source": "2",
                        "$premium": "1",
                        "$": "Turnhere"
                    }
                ]
            },
            "videoFiles": {
                "videoFile": [
                    {
                        "$formatCode": "1002",
                        "$msnFileId": "0304FE9B-4BCE-4955-AC3C-A34C2203F3C1",
                        "$height": "240",
                        "$width": "320",
                        "$bitrate": "446",
                        "uri": {
                            "$": "http\x3a\x2f\x2fcontent3.catalog.video.msn.com\x2fe2\x2fds\x2fus\x2fTurnhere\x2fTurnHere\x2fCC4C4482-B5A8-4829-9CAB-CC104AE628C1.wmv"
                        }
                    },
                    {
                        "$formatCode": "1003",
                        "uri": {
                            "$": "http\x3a\x2f\x2fcontent3.catalog.video.msn.com\x2fe2\x2fhttp\x3a\x2f\x2fcdn.videos.turnhere.com\x2fflv8\x2fvenicebeach.flv"
                        }
                    }
                ]
            },
            "files": {
                "file": [
                    {
                        "$formatCode": "2007",
                        "uri": {
                            "$": "http\x3a\x2f\x2fcdn.videos.turnhere.com\x2fimages92x69\x2fVENICEBEACH.jpg"
                        }
                    }
                ]
            },
            "extendedXml": {
                "$": ""
            },
            "subTitle": {
                "$": null
            },
            "copyright": {
                "$": null
            },
            "usage": {
                "usageItem": [
                    {
                        "$counterType": "1",
                        "$hourlyCount": "0",
                        "$hourlyChange": "0",
                        "$dailyCount": "0",
                        "$weeklyCount": "0",
                        "$monthlyCount": "2",
                        "$totalCount": "1977",
                        "$totalAverage": "1.05"
                    }
                ]
            }
        },
        {
            "$publishState": "Published",
            "$lcid": "1033",
            "$options": "0",
            "$version": "29",
            "$filterFlags": "9103",
            "uuid": {
                "$ref": "6ms12ek",
                "$seoMetaData": "\x2fvideo\x2fbush-meets-teen-sensation\x2f",
                "$": "695fc4de-0cee-495c-b3df-31c0b0e5d574"
            },
            "providerId": {
                "$": "n_bush_basketball_060314"
            },
            "csId": {
                "$": "Msnbc"
            },
            "source": {
                "$friendlyName": "NBC Sports",
                "$": "NBC Sports"
            },
            "pageGroup": {
                "$": "MSVROM"
            },
            "title": {
                "$": "Bush meets teen sensation"
            },
            "description": {
                "$": "March 14\x3a President Bush meets with Jason McElwain, the autistic 17-year-old high schooler who became an instant star by scoring 20 points and making six three-pointers in his first game last month."
            },
            "durationSecs": {
                "$": 10
            },
            "startDate": {
                "$": "2006-03-13T16\x3a00\x3a00Z"
            },
            "activeEndDate": {
                "$": "2099-12-31T00\x3a00\x3a00Z"
            },
            "searchableEndDate": {
                "$": "2099-12-31T00\x3a00\x3a00Z"
            },
            "archiveEndDate": {
                "$": "2099-12-31T00\x3a00\x3a00Z"
            },
            "tags": {
                "tag": [
                    {
                        "$market": "us",
                        "$namespace": "Duration",
                        "$source": "2",
                        "$premium": "1",
                        "$": "short"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Genre",
                        "$source": "5",
                        "$premium": "1",
                        "$": "Sports"
                    },
                    {
                        "$market": "us",
                        "$namespace": "mobile",
                        "$source": "5",
                        "$premium": "0",
                        "$": "mobile_rights"
                    },
                    {
                        "$market": "us",
                        "$namespace": "msnbcid",
                        "$source": "2",
                        "$premium": "0",
                        "$": "11825895"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Cat",
                        "$source": "2",
                        "$premium": "0",
                        "$": "NBC Sports"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Cat",
                        "$source": "2",
                        "$premium": "0",
                        "$": "Other"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top",
                        "$source": "2",
                        "$premium": "0",
                        "$": "News"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top_Cat",
                        "$source": "2",
                        "$premium": "0",
                        "$": "News_Other"
                    },
                    {
                        "$market": "us",
                        "$namespace": "MSNVideo_Top_Cat",
                        "$source": "5",
                        "$premium": "0",
                        "$": "Source_NBC Sports"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "4",
                        "$premium": "0",
                        "$": "bush meets"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "Msnbc"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "MSNBC News"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "News"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "sports"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "Sports news"
                    },
                    {
                        "$market": "us",
                        "$namespace": "Public",
                        "$source": "2",
                        "$premium": "0",
                        "$": "Video"
                    },
                    {
                        "$market": "us",
                        "$namespace": "VC_Source",
                        "$source": "2",
                        "$premium": "1",
                        "$": "Msnbc\x3aNBC Sports"
                    },
                    {
                        "$market": "us",
                        "$namespace": "VC_Supplier",
                        "$source": "2",
                        "$premium": "1",
                        "$": "Msnbc"
                    }
                ]
            },
            "videoFiles": {
                "videoFile": [
                    {
                        "$formatCode": "1002",
                        "$height": "240",
                        "$width": "320",
                        "$bitrate": "200",
                        "uri": {
                            "$": "http\x3a\x2f\x2fwww.msnbc.msn.com\x2fdefault.cdnx\x2fid\x2f11825895\x2fdisplaymode\x2f1157\x2f"
                        }
                    },
                    {
                        "$formatCode": "1003",
                        "uri": {
                            "$": "http\x3a\x2f\x2fwww.msnbc.msn.com\x2fdefault.cdnx\x2fid\x2f11825895\x2fdisplaymode\x2f1157\x2f\x3ft\x3d.FLV"
                        }
                    }
                ]
            },
            "files": {
                "file": [
                    {
                        "$formatCode": "2007",
                        "uri": {
                            "$": "http\x3a\x2f\x2fmsnbcmedia.msn.com\x2fj\x2fmsnbc\x2fComponents\x2fVideo\x2f060314\x2fn_bush_basketball_060314.vmod.jpg"
                        }
                    }
                ]
            },
            "extendedXml": {
                "relatedLinks": {
                    "link": [
                        {
                            "$url": "http\x3a\x2f\x2fwww.msnbc.msn.com\x2fid\x2f3032113\x2f",
                            "$": "NBC Sports Front Page"
                        },
                        {
                            "$url": "http\x3a\x2f\x2fwww.msnbc.msn.com\x2f",
                            "$": "Latest news from MSNBC.com"
                        },
                        {
                            "$url": "http\x3a\x2f\x2fwww.msnbc.msn.com\x2fid\x2f3032092\x2f",
                            "$": "MSNBC.com\x27s News Section"
                        }
                    ]
                }
            },
            "subTitle": {
                "$": null
            },
            "copyright": {
                "$": null
            },
            "usage": {
                "usageItem": [
                    {
                        "$counterType": "1",
                        "$hourlyCount": "0",
                        "$hourlyChange": "0",
                        "$dailyCount": "0",
                        "$weeklyCount": "0",
                        "$monthlyCount": "1",
                        "$totalCount": "635",
                        "$totalAverage": "1.13"
                    }
                ]
            }
        }
    ],
    "$": ""
}

4 个答案:

答案 0 :(得分:2)

你试过吗

dataType: "json",

而不是

dataType: "application/json",

因为你的json代码没有任何问题。

http://jsfiddle.net/HWUvj/2/

答案 1 :(得分:1)

刚试了一个当地的例子:

$(function(){
  $.get('test.php', function(data) {
    alert(data.$test);
  });
});

test.php是json输出:

<?php header("Content-type: application/json");?>
{
  "$test": "test",
  "$lala": {
    "$rofl": "$copter",
    "blubb": "test"
  }
}

像魅力一样工作。没有内容类型标题我收到与你相同的错误,因为它只是一个文本而不是json:)

答案 2 :(得分:0)

$不是未定义值的原因,因为它是正确的JSON命名字符。
我相信data.$tracking应该有效。您也可以尝试data['$tracking'] 或者尝试data.d.$tracking 同时将dataType设置为'json',将contentType设置为'application/json' 在我看来,您应该调试此代码并只是跟踪data并找到所有问题。 StackOverflow的成员不应该跟踪我们所有的json-dump并查找错误,很难读取这么多无用的数据。

答案 3 :(得分:0)

我认为你正确地设置了数据类型,因为JSON是正确的。

应该是

  dataType: "json"

documentation中所述。

编辑 - 因为你正在调用另一台服务器,你必须使用jsonp,所以设置:

  dataType: "json",
  crossDomain: "true"