TheMovieDB API Uncaught SyntaxError:JSON中位置0处的意外令牌u

时间:2019-08-06 01:00:54

标签: jquery json

我当前正在使用一个API,该API返回JSON输出,还有一个电影API,我可以100%工作,但是我不能让TV API工作。以下是电影API和结果:

<script>
   var settings = {
   "async": true,
   "crossDomain": true,
   "url": "https://api.themoviedb.org/3/movie/tt6806448?language=en-US&api_key={API_Key}",
   "method": "GET",
   "headers": {},
   "data": "{}"
   }

   $.ajax(settings).done(function (response) {
   document.getElementById('description').innerHTML = JSON.parse(JSON.stringify(response.overview, undefined, 2))
   });
</script>

JSON输出:

{  
   "adult":false,
   "backdrop_path":"/hpgda6P9GutvdkDX5MUJ92QG9aj.jpg",
   "belongs_to_collection":null,
   "budget":200000000,
   "genres":[  
      {  
         "id":28,
         "name":"Action"
      }
   ],
   "homepage":"https://www.hobbsandshawmovie.com",
   "id":384018,
   "imdb_id":"tt6806448",
   "original_language":"en",
   "original_title":"Fast & Furious Presents: Hobbs & Shaw",
   "overview":"A spinoff of The Fate of the Furious, focusing on Johnson's US Diplomatic Security Agent Luke Hobbs forming an unlikely alliance with Statham's Deckard Shaw.",
   "popularity":452.935,
   "poster_path":"/keym7MPn1icW1wWfzMnW3HeuzWU.jpg",
   "production_companies":[  
      {  
         "id":33,
         "logo_path":"/8lvHyhjr8oUKOOy2dKXoALWKdp0.png",
         "name":"Universal Pictures",
         "origin_country":"US"
      }
   ],
   "production_countries":[  
      {  
         "iso_3166_1":"US",
         "name":"United States of America"
      }
   ],
   "release_date":"2019-08-01",
   "revenue":0,
   "runtime":136,
   "spoken_languages":[  
      {  
         "iso_639_1":"en",
         "name":"English"
      },
      {  
         "iso_639_1":"it",
         "name":"Italiano"
      }
   ],
   "status":"Released",
   "tagline":"",
   "title":"Fast & Furious Presents: Hobbs & Shaw",
   "video":false,
   "vote_average":6.6,
   "vote_count":221
}

结果:

[说明]

但是,当我使用TV API时,我只会收到错误消息:

Uncaught SyntaxError: Unexpected token u in JSON at position 0

下面是我用于电视API的JavaScript,类似于电影API。

<script>
   var settings = {
   "async": true,
   "crossDomain": true,
   "url": "https://api.themoviedb.org/3/find/tt0944947?api_key={API_Key}&language=en-US&external_source=imdb_id",
   "method": "GET",
   "headers": {},
   "data": "{}"
   }

   $.ajax(settings).done(function (response) {
   document.getElementById('description').innerHTML = JSON.parse(JSON.stringify(response.overview, undefined, 2))
   });
</script>

JSON输出:

{  
   "adult":false,
   "backdrop_path":"/hpgda6P9GutvdkDX5MUJ92QG9aj.jpg",
   "belongs_to_collection":null,
   "budget":200000000,
   "genres":[  
      {  
         "id":28,
         "name":"Action"
      }
   ],
   "homepage":"https://www.hobbsandshawmovie.com",
   "id":384018,
   "imdb_id":"tt6806448",
   "original_language":"en",
   "original_title":"Fast & Furious Presents: Hobbs & Shaw",
   "overview":"A spinoff of The Fate of the Furious, focusing on Johnson's US Diplomatic Security Agent Luke Hobbs forming an unlikely alliance with Statham's Deckard Shaw.",
   "popularity":452.935,
   "poster_path":"/keym7MPn1icW1wWfzMnW3HeuzWU.jpg",
   "production_companies":[  
      {  
         "id":33,
         "logo_path":"/8lvHyhjr8oUKOOy2dKXoALWKdp0.png",
         "name":"Universal Pictures",
         "origin_country":"US"
      }
   ],
   "production_countries":[  
      {  
         "iso_3166_1":"US",
         "name":"United States of America"
      }
   ],
   "release_date":"2019-08-01",
   "revenue":0,
   "runtime":136,
   "spoken_languages":[  
      {  
         "iso_639_1":"en",
         "name":"English"
      },
      {  
         "iso_639_1":"it",
         "name":"Italiano"
      }
   ],
   "status":"Released",
   "tagline":"",
   "title":"Fast & Furious Presents: Hobbs & Shaw",
   "video":false,
   "vote_average":6.6,
   "vote_count":221
}

1 个答案:

答案 0 :(得分:0)

如果u位于位置0,但您没有看到它-这可能意味着该文件具有Unicode BOM字符。在十六进制查看器中打开JSON文件,然后查看7B之前是否有字节。