2017-07-20 59 views
0

我有從JSON對象獲取數據的問題JSONP不起作用。 拳頭我收到一個抱怨json格式的錯誤。阿賈克斯檢索時,我調用外部URL

$.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", 
       " 
      } 
     ] 
    } 
} 
+0

了'json'格式確實是錯誤的。它應該是'}]'而不是']'(最後一個括號)和最後一個'''。你可以在[JSONLint](https://jsonlint.com/) – Dhyey

+0

中檢查它是一個錯字。 json對象確實具有}] – user1830053

回答

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" 
      } 
     }] 
    } 
}