【问题标题】:Flutter http.get is giving an Exception while fetching data from RapidApiFlutter http.get 在从 RapidApi 获取数据时出现异常
【发布时间】:2021-07-07 05:44:49
【问题描述】:

我一直在创建一个应用程序,过去 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"
}

【问题讨论】:

    标签: android flutter request flutter-dependencies rapidapi


    【解决方案1】:

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

    Unhandled Exception: InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 2019-06-19
      • 2012-09-23
      • 2014-03-04
      • 2022-12-14
      • 2021-06-10
      相关资源
      最近更新 更多