Flutter 修复了在Flatter中从API获取数据时出现的格式化异常错误

Flutter 修复了在Flatter中从API获取数据时出现的格式化异常错误,flutter,fetch,Flutter,Fetch,这是我的全部代码。它相对较短,因为我正在尝试从invidiou.sh api获取视频标题和视频id:“” 如果打印出API响应的正文,您可以找到: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta charset="UTF-8">

这是我的全部代码。它相对较短,因为我正在尝试从invidiou.sh api获取视频标题和视频id:“”


如果打印出API响应的正文,您可以找到:

 <!DOCTYPE HTML>
  <html lang="en-US">

  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <title>Challenge Failed! vDDoS Security</title>
  </head>

  <body>
    <table width="100%" height="100%" cellpadding="30">
      <tr>
        <td align="center" valign="center">

          <h1 data-translate="challenge_headline" style="background-color:                white; border: 0px; color: #404040; font-family: &quot;Open Sans&quot;, Helvetica,      Arial, sans-serif; font-size: 5vw; font-stretch: inherit; font-variant-numeric: inherit; font-weight: 300; line-height: 1.2; margin: 0px; padding: 0px; vertical-     align: baseline;">
            vDDoS Security</h1>

          <noscript>
            <h1 style="text-align:center;color:red;">
              <strong>Please turn JavaScript on and reload the page.</strong>
            </h1>
          </noscript>

挑战失败!vDDoS安全
vDDoS安全
请打开JavaScript并重新加载页面。

因此,如果没有javascript,这个API将无法工作,因为vDDOS安全性无法在移动设备上工作

实际上,您的响应返回的是列表而不是地图


试试这个!(但我不确定
我不知道什么是vDDOS安全性,但我尝试用python做同样的事情,效果很好。我使用了requests模块。有没有办法解决这个问题,或者干脆不可能在flifter中实现。据我所知,由于javascript不可用,在任何移动平台上都无法实现,应该这样做从服务器端进行修补。
Exception has occurred.
FormatException (FormatException: Unexpected character (at character 1)
<!DOCTYPE HTML>
^
)
Future<Album> fetchAlbum() async {
  final response =
      await http.get('https://invidiou.sh/api/v1/search?q=Corridor+Crew');

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response, then parse the JSON.
    return Album.fromJson(json.decode(response.body)); <---- HERE!
  } else {
    // If the server did not return a 200 OK response, then throw an exception.
    throw Exception('Failed to load album');
  }
}
 <!DOCTYPE HTML>
  <html lang="en-US">

  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <title>Challenge Failed! vDDoS Security</title>
  </head>

  <body>
    <table width="100%" height="100%" cellpadding="30">
      <tr>
        <td align="center" valign="center">

          <h1 data-translate="challenge_headline" style="background-color:                white; border: 0px; color: #404040; font-family: &quot;Open Sans&quot;, Helvetica,      Arial, sans-serif; font-size: 5vw; font-stretch: inherit; font-variant-numeric: inherit; font-weight: 300; line-height: 1.2; margin: 0px; padding: 0px; vertical-     align: baseline;">
            vDDoS Security</h1>

          <noscript>
            <h1 style="text-align:center;color:red;">
              <strong>Please turn JavaScript on and reload the page.</strong>
            </h1>
          </noscript>
Future<List<Album>> fetchAlbum() async {

  List<Album> albums =[];
  final response =
      await http.get('https://invidiou.sh/api/v1/search?q=Corridor+Crew');

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response, then parse the JSON.
    List<Map<String,dynamic>> list = List.from(response.body);
    for(Map<String,dynamic> m in list)
         albums.add(Album.fromJson(m));

    return albums;
  } else {
    // If the server did not return a 200 OK response, then throw an exception.
    throw Exception('Failed to load album');
  }
}