Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图从html解析dart中的信息,我需要一些代码方面的帮助_Html_Flutter_Dart - Fatal编程技术网

试图从html解析dart中的信息,我需要一些代码方面的帮助

试图从html解析dart中的信息,我需要一些代码方面的帮助,html,flutter,dart,Html,Flutter,Dart,我正在尝试编写一个用于观看电影的应用程序,通常从网站获取其内容,例如“” 因此,从“class=“boxtitle”加载标题,从“class=“boxdetil”加载详细信息 但我这里有一个错误: import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; Future<Post> fetchPost() async { fina

我正在尝试编写一个用于观看电影的应用程序,通常从网站获取其内容,例如“” 因此,从“class=“boxtitle”加载标题,从“class=“boxdetil”加载详细信息 但我这里有一个错误:

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

Future<Post> fetchPost() async {
  final response =
  await http.get('http://ww.cima4u.tv/category/%d8%a7%d9%81%d9%84%d8%a7%d9%85-%d8%a7%d8%ac%d9%86%d8%a8%d9%8a-movies-english/');

  if (response.statusCode == 200) {
    // If the call to the server was successful, parse the JSON.
    return Post.fromJson(json.decode(response.body));
  } else {
    // If that call was not successful, throw an error.
    throw Exception('Failed to load post');
  }
}

class Post {

  final String boxtitle;
  final String boxdetil;

  Post({this.boxtitle, this.boxdetil});

  factory Post.fromJson(Map<String, dynamic> json) {
    return Post(
      boxtitle: json['boxtitle'],
      boxdetil: json['boxdetil'],
    );
  }
}

void main() => runApp(MyApp(post: fetchPost()));

class MyApp extends StatelessWidget {
  final Future<Post> post;

  MyApp({Key key, this.post}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fetch Data Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Fetch Data Example'),
        ),
        body: Center(
          child: FutureBuilder<Post>(
            future: post,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return Text(snapshot.data.boxtitle);
              } else if (snapshot.hasError) {
                return Text("${snapshot.error}");
              }

              // By default, show a loading spinner.
              return CircularProgressIndicator();
            },
          ),
        ),
      ),
    );
  }
}```
the error :
formatexception unexpected character (at character 1)
导入'dart:convert';
进口“包装:颤振/材料.省道”;
将“package:http/http.dart”导入为http;
Future fetchPost()异步{
最后答复=
等待http.get('http://ww.cima4u.tv/category/%d8%a7%d9%81%d9%84%d8%a7%d9%85-%d8%a7%d8%ac%d9%86%d8%a8%d9%8a电影(英语/);
如果(response.statusCode==200){
//如果对服务器的调用成功,则解析JSON。
return Post.fromJson(json.decode(response.body));
}否则{
//如果该调用未成功,则抛出一个错误。
抛出异常(“加载post失败”);
}
}
班岗{
最终字符串标题;
最终字符串boxdetil;
Post({this.boxtitle,this.boxdetil});
factory Post.fromJson(映射json){
回程站(
boxtitle:json['boxtitle'],
boxdetil:json['boxdetil'],
);
}
}
void main()=>runApp(MyApp(post:fetchPost());
类MyApp扩展了无状态小部件{
未来最后员额;
MyApp({Key-Key,this.post}):超级(Key:Key);
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“获取数据示例”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
appBar:appBar(
标题:文本(“获取数据示例”),
),
正文:中(
孩子:未来建设者(
未来:邮政,
生成器:(上下文,快照){
if(snapshot.hasData){
返回文本(snapshot.data.boxtitle);
}else if(snapshot.hasrerror){
返回文本(“${snapshot.error}”);
}
//默认情况下,显示加载微调器。
返回循环ProgressIndicator();
},
),
),
),
);
}
}```
错误:
formatexception意外字符(在字符1处)
您可以参考此答案您可以参考此答案