0

我一直在创建一个应用程序,并且在过去 2 天里一直被困在这个问题上,没有任何进展。从互联网获取数据时,http.get 请求给了我一个例外。这是我正在尝试集成到我的应用程序中的快速 API ( IMDB )。我将为您提供我的代码以便更好地理解。

这是获取请求:

class NetworkGetRequest {
  static Future<Map<String, Object>> getRequestWithQueryParameter(Map<String, dynamic> queryParameters, String url) async {
    Map<String, Object> result = new Map();
    final headers = {
      "content-type": "application/json",
      "x-rapidapi-key": <YOUR-API-KEY>,
      "x-rapidapi-host": "movie-database-imdb-alternative.p.rapidapi.com",
      "useQueryString": true
    };
    try {
      final uri = Uri.https(url, "", queryParameters);
      var response = await http.get(uri, headers: headers);
      Map<String, Object> responseMap = jsonDecode(response.body);
      result['data'] = responseMap;
      return result;
    } catch (e) {
      result['error'] = 'Exception  : ' + e.toString();
      return result;
    }
  }

这就是我调用 API 的方式:

Map<String, Object> result = new Map();
Map<String, dynamic> queryParam = {
  'i': 'tt12361974',
  'r': 'json',
  'plot': 'full'
};
String url = 'movie-database-imdb-alternative.p.rapidapi.com';
result = await NetworkGetRequest.getRequestWithQueryParameter(queryParam, URL);

这是我从中得到的例外:

type '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'Map<String, String>?'

这是我期望从服务器获得的 JSON:

{
"Title": "Zack Snyder's Justice League",
"Year": "2021",
"Rated": "R",
"Released": "18 Mar 2021",
"Runtime": "242 min",
"Genre": "Action, Adventure, Fantasy",
"Director": "Zack Snyder",
"Writer": "Jerry Siegel, Joe Shuster, Zack Snyder",
"Actors": "Henry Cavill, Ben Affleck, Gal Gadot",
"Plot": "Determined to ensure Superman's ultimate sacrifice was not in vain, Bruce Wayne aligns forces with Diana Prince with plans to recruit a team of metahumans to protect the world from an approaching threat of catastrophic proportions. The task proves more difficult than Bruce imagined, as each of the recruits must face the demons of their own pasts to transcend that which has held them back, allowing them to come together, finally forming an unprecedented league of heroes. Now united, Batman, Wonder Woman, Aquaman, Cyborg and The Flash may be too late to save the planet from Steppenwolf, DeSaad and Darkseid and their dreadful intentions.",
"Language": "English, Icelandic, French",
"Country": "United States, United Kingdom",
"Awards": "1 nomination",
"Poster": "https://m.media-amazon.com/images/M/MV5BYjI3NDg0ZTEtMDEwYS00YWMyLThjYjktMTNlM2NmYjc1OGRiXkEyXkFqcGdeQXVyMTEyMjM2NDc2._V1_SX300.jpg",
"Ratings": [
    {
        "Source": "Internet Movie Database",
        "Value": "8.1/10"
    },
    {
        "Source": "Metacritic",
        "Value": "54/100"
    }
],
"Metascore": "54",
"imdbRating": "8.1",
"imdbVotes": "308,599",
"imdbID": "tt12361974",
"Type": "movie",
"DVD": "N/A",
"BoxOffice": "N/A",
"Production": "N/A",
"Website": "N/A",
"Response": "True"
}
4

1 回答 1

0

我相信 API 或 RapidAPI 没有任何问题,除了未处理的期望之外,一切都很好。转到此问题以解决此异常。

未处理的异常:InternalLinkedHashMap<String, dynamic>' 不是 'List<dynamic> 类型的子类型

于 2021-09-17T10:06:08.453 回答