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

时间:2019-07-11 07:19:13

标签: html flutter dart

我试图编写一个用于观看电影的应用程序,该应用程序通常是从网站上获取其内容,例如“ 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/” 因此,请从“ 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)

0 个答案:

没有答案