大家好,我正在尝试从Prestashop API检索JSON数据 我有例外,所以无法得到他们 我想要做的是检索从此URL:获取的JSON数据的集合 下面的文件是我用来通过具有不同API且没有标题的API从Internet检索数据的文件,我可以正确获取数据,但也许Prestashop API需要其他东西
Future<Album> fetchAlbum() async {
final response = await http.get(
'https://uibox.store/api/customers/1&output_format=JSON',
headers: {HttpHeaders.authorizationHeader: "4f34f134f134f3c14f1234c1234c134c134rcwdth"},
);
final responseJson = json.decode(response.body);
return Album.fromJson(responseJson);
}
class Album {
final int userId;
final int id;
final String lastname;
Album({this.userId, this.id, this.lastname});
factory Album.fromJson(Map<String, dynamic> json) {
return Album(
userId: json['userId'],
id: json['id'],
lastname: json['lastname'],
);
}
}
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<Album> futureAlbum;
@override
void initState() {
super.initState();
futureAlbum = fetchAlbum();
}
@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<Album>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Row(children: [
Text(snapshot.data.lastname),]);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
},
),
),
),
);
}
}