[英]FormatException: Unexpected end of input (at character 1) with OSM map
I am trying to get all the markers out of my API (it is about 3k points at the same time) and put them on the OSM map. I parsed JSON and put the necessary list in the http-request.I also use a loop inside the widget and try to put all the points I need through the loop and make them appear on the OSM map. But now I got this error:我试图从我的 API 中取出所有标记(同时大约有 3k 个点)并将它们放在 OSM map 上。我解析了 JSON 并将必要的列表放在 http-request 中。我还使用了一个循环在小部件内部并尝试通过循环放置我需要的所有点并使它们出现在 OSM map 上。但现在我收到此错误:
I/flutter (25693): FormatException: Unexpected end of input (at character 1)
I/flutter (25693):
I/flutter (25693): ^
My model:我的model:
List<Stop> stopFromJson(String str) => List<Stop>.from(json.decode(str).map((x) => Stop.fromJson(x)));
String stopToJson(List<Stop> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Stop {
Stop({
this.stLat,
this.stLong,
});
final double stLat;
final double stLong;
Http-request is: Http 请求是:
Future<List<Stop>> fetchStops() async {
String username = '';
String password = '';
String basicAuth =
'Basic ' + base64Encode(utf8.encode('$username:$password'));
print(basicAuth);
final response = await http.get(
Uri.parse(
link),
headers: <String, String>{'authorization': basicAuth});
var jsonResponse = convert.jsonDecode(response.body) as List;
return jsonResponse.map((e) => Stop.fromJson(e)).toList();
The loop inside widget where i try to iterate all over the ppints and put them om the map:小部件内的循环,我尝试遍历所有 ppint 并将它们放在 map 中:
@override
void initState() {
futureStops = fetchStops();
super.initState();
}
List<Stop> listStops;
Future<List<Stop>> futureStops;
List<Marker> allMarkers = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: FutureBuilder(
future: futureStops,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
listStops = snapshot.data;
listStops.forEach((Stops) {
allMarkers = listStops.map(
(e) => Marker(
width: 1,
height: 1,
point: latLong.LatLng(e.stLat, e.stLat),
builder: (_) => Icon(
Icons.person_pin,
color: Colors.green,
)),
).toList(growable: true);;
});
I don't understand what exactly is going wrong, because it seems that I parsed everything correctly and everything should work, but I still get this error.我不明白究竟出了什么问题,因为似乎我正确地解析了所有内容并且一切都应该正常工作,但我仍然收到此错误。 With what it can be connected?它可以连接什么? Where exactly did I go wrong?我go到底哪里错了? I would really appreciate your help.我将衷心感谢您的帮助。
FIX THIS ISSUE Also it seems to me that the error is somewhere here:修复此问题在我看来,错误也出在此处:
factory Stop.fromJson(Map<String, dynamic> json) => Stop(
stLat: json["st_lat"],
stLong: json["st_long"],
Fix it: the issue was about parsing: Should be like that: stLat: json["st_lat"].toDouble(), stLong: json["st_long"].toDouble()
, I was pretty sure I did everything correctly, but somehow it didn't parse as I wanted.解决它:问题是关于解析:应该是这样的: stLat: json["st_lat"].toDouble(), stLong: json["st_long"].toDouble()
,我很确定我做的一切都是正确的,但是不知何故,它没有按照我的意愿进行解析。 Now all fixed.现在都修好了。
For anyone who will going to take the code of loop from my question: it dosen't work.对于将从我的问题中获取循环代码的任何人:它不起作用。 I will try to solve it and paste here the answer.我会尝试解决它并在此处粘贴答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.