我试图解析json,将其打印到控制台,然后放入ListView.builder并得到这个错误:键入'_InternalLinkedHashMap
我要怎么修?
列表数据
FutureBuilder(
future: restaurantSearch,
builder: (context, AsyncSnapshot<RestaurantSearch> snapshot) {
if(snapshot.connectionState == ConnectionState.waiting) {
return Expanded(child: Center(child: CircularProgressIndicator(strokeWidth: 3)));
} else if(snapshot.connectionState == ConnectionState.done) {
if(snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.restaurants.length,
itemBuilder: (context, index) {
var restaurant = snapshot.data.restaurants[index];
return ListTile(
title:Text(restaurant.name),
);
}
);
}
} else if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
}
return Text('');
}
)
API服务
Future<RestaurantSearch> restaurantSearch(String query) async {
final response = await dio.get("https://restaurant-api.dicoding.dev/search", queryParameters: {"q": query});
print(response.data);
if(response.statusCode == 200) {
return RestaurantSearch.fromJson(json.decode(response.data));
} else {
throw Exception("Failed to Load Detail Restaurant, Please Check Your Internet");
}
}
模型
import 'dart:convert';
RestaurantSearch restaurantSearchFromJson(String str) => RestaurantSearch.fromJson(json.decode(str));
String restaurantSearchToJson(RestaurantSearch data) => json.encode(data.toJson());
class RestaurantSearch {
RestaurantSearch({
this.error,
this.founded,
this.restaurants,
});
bool error;
int founded;
List<RestaurantS> restaurants;
factory RestaurantSearch.fromJson(Map<String, dynamic> json) => RestaurantSearch(
error: json["error"],
founded: json["founded"],
restaurants: List<RestaurantS>.from(json["restaurants"].map((x) => RestaurantS.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"error": error,
"founded": founded,
"restaurants": List<String>.from(restaurants.map((x) => x.toJson())),
};
}
class RestaurantS {
RestaurantS({
this.id,
this.name,
this.description,
this.pictureId,
this.city,
this.rating,
});
String id;
String name;
String description;
String pictureId;
String city;
double rating;
factory RestaurantS.fromJson(Map<String, dynamic> json) => RestaurantS(
id: json["id"],
name: json["name"],
description: json["description"],
pictureId: json["pictureId"],
city: json["city"],
rating: json["rating"].toDouble(),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"pictureId": pictureId,
"city": city,
"rating": rating,
};
}
非常感谢您的回答........................................................................................................................................................................................................................
换行
return RestaurantSearch.fromJson(response.data);
我正在开发我的flutter应用程序的身份验证。请帮我解决这个问题。我无法识别返回这样一个错误的问题,声明未处理异常:类型列表不是类型字符串的子类型。 以下是登录屏幕的代码: 执行登录的上述代码部分: 错误
上面的代码给出了警告未处理的异常:类型'double'不是类型'string'的子类型
我收到了错误消息: 被精确定位的线在这里: 返回类型为
我正在尝试从服务器获取json数据
更新:感谢@Rjulcaa回答我的地图现在是一个列表,但是列表没有显示在用户界面上。我转过来,我需要用FutureBuilder来处理未来,所以如果有人面临这个问题,记得在你的用户界面主体中添加一个FutureBuilder,并在构建器上返回你想要显示的小部件。 我正在制作一个todo列表教程,我正在尝试添加JSON上的编码功能,我的todoList将其保存在SharedReferences上,当
我有这个变量问题,这是我的函数 我犯了这个错误 正在执行热重新加载。。。在902毫秒内重新加载了594个库中的14个。E/flatter(4211):[错误:flatter/lib/ui/ui#dart_state.cc(148)]未处理的异常:类型“String”不是“index”E/flatter(4211)的类型“int”的子类型:\0 DatabaseHelper。getData(包:fl