当我调用外部URL时,检索jsonp的Ajax不起作用

时间:2017-07-20 16:15:45

标签: json

我在从json对象获取数据时遇到问题。 拳头我收到一个抱怨json格式的错误。

   $.ajax({
    url: "http://www.test.com&callback=?&format=json",
    type: 'POST',
    dataType: "json",
    beforeSend: function(xhr) {
        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    }
})
.done(function(response) {
    console.log(response.assets);
})
.fail(function(response) {
    console.log(response.assets);
});

这是json对象。我怎么能得到 1.总计 2.文件ID 3. Medatadata值

{
    "total": "1",
    "included": "1",
    "start": "0",
    "status": "200",
    "results": {
        "assets": [{
            "uri": "/document/id/1c0cf9cb6b8e529c8b1b0a91db37742e",
            "context": "51216a3c6b28719c56d0665f538f8e3e",
            "id": "1c0cf9cb6b8e529c8b1b0a91db37742e",
            "path": "templatedata/rockwellautomation/publication/data/blog/VBTestDCRLocalizationUA_20170510-1102.xml",
            "metadata": {
                "TeamSite/Metadata/industry": "",
                "TeamSite/Metadata/Locale": "en_US",
                "TeamSite/Metadata/name_twitter-description": "Test DCR Localization UAT",
                "TeamSite/Metadata/property_og-image": "/resources/images/rockwellautomation/share/MPI_IoT_Study_Executive_Summary_2016--photograph_1200w1200h.jpg",
                "
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:1)

你的json错了。元数据有很多错误。

这是一个很好的版本,可以让它运行。

{
    "total": "1",
    "included": "1",
    "start": "0",
    "status": "200",
    "results": {
        "assets": [{
            "uri": "/document/id/1c0cf9cb6b8e529c8b1b0a91db37742e",
            "context": "51216a3c6b28719c56d0665f538f8e3e",
            "id": "1c0cf9cb6b8e529c8b1b0a91db37742e",
            "path": "templatedata/rockwellautomation/publication/data/blog/VBTestDCRLocalizationUA_20170510-1102.xml",
            "metadata": {
                "TeamSite/Metadata/industry": "",
                "TeamSite/Metadata/Locale": "en_US",
                "TeamSite/Metadata/name_twitter-description": "Test DCR Localization UAT",
                "TeamSite/Metadata/property_og-image": "/resources/images/rockwellautomation/share/MPI_IoT_Study_Executive_Summary_2016--photograph_1200w1200h.jpg"
            }
        }]
    }
}