解码uri.https时的错误,“未经手的异常:formatexception:无效的字符(在字符27)”
我正在尝试构建天气应用程序。我已经搜索了天气API,因为我需要每小时和每周进行天气预报。我找到了这个网站 https://www.visualcrossing.com/ 。我想像这样解码HTTP链接(以下在代码中):
class DataServiceOneCall {
Future<WeatherResponseOnecall> getWeatherOneCall(String city) async {
//https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/Olszowice?unitGroup=metric&key=QVDLJFCCQRM5296M7J975FP2W&contentType=json
final queryParameters = {
'q': city,
'unitGroup': 'metric',
'key': 'QVDLJFCCQRM5296M7J975FP2W',
'contentType': 'json',
};
final uri = Uri.https(
'weather.visualcrossing.com/VisualCrossingWebServices',
'/rest/services/timeline,',
queryParameters);
final response_onecall = await http.get(uri);
print(response_onecall.body);
final json = jsonDecode(response_onecall.body);
return WeatherResponseOnecall.fromJson(json);
}
}
我有这样的错误。
E/flutter (11332): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Invalid character (at character 27)
E/flutter (11332): weather.visualcrossing.com/VisualCrossingWebServices
E/flutter (11332): ^
E/flutter (11332):
E/flutter (11332): #0 _Uri._fail (dart:core/uri.dart:1754:5)
E/flutter (11332): #1 _Uri._normalizeRegName (dart:core/uri.dart:2252:9)
E/flutter (11332): #2 _Uri._makeHost (dart:core/uri.dart:2113:12)
E/flutter (11332): #3 new _Uri (dart:core/uri.dart:1640:12)
E/flutter (11332): #4 _Uri._makeHttpUri (dart:core/uri.dart:1813:12)
E/flutter (11332): #5 new _Uri.https (dart:core/uri.dart:1678:12)
E/flutter (11332): #6 DataServiceOneCall.getWeatherOneCall package:weather_app/data_service/data_service_onecall.dart:18
感谢您的帮助。
I'm trying to built weather app. I've searched weather API's, because I need make hourly and weekly weather forecast. I found this website https://www.visualcrossing.com/. I want to decode HTTP link (below in code) like this:
class DataServiceOneCall {
Future<WeatherResponseOnecall> getWeatherOneCall(String city) async {
//https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/Olszowice?unitGroup=metric&key=QVDLJFCCQRM5296M7J975FP2W&contentType=json
final queryParameters = {
'q': city,
'unitGroup': 'metric',
'key': 'QVDLJFCCQRM5296M7J975FP2W',
'contentType': 'json',
};
final uri = Uri.https(
'weather.visualcrossing.com/VisualCrossingWebServices',
'/rest/services/timeline,',
queryParameters);
final response_onecall = await http.get(uri);
print(response_onecall.body);
final json = jsonDecode(response_onecall.body);
return WeatherResponseOnecall.fromJson(json);
}
}
And I've got error thrown like this.
E/flutter (11332): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Invalid character (at character 27)
E/flutter (11332): weather.visualcrossing.com/VisualCrossingWebServices
E/flutter (11332): ^
E/flutter (11332):
E/flutter (11332): #0 _Uri._fail (dart:core/uri.dart:1754:5)
E/flutter (11332): #1 _Uri._normalizeRegName (dart:core/uri.dart:2252:9)
E/flutter (11332): #2 _Uri._makeHost (dart:core/uri.dart:2113:12)
E/flutter (11332): #3 new _Uri (dart:core/uri.dart:1640:12)
E/flutter (11332): #4 _Uri._makeHttpUri (dart:core/uri.dart:1813:12)
E/flutter (11332): #5 new _Uri.https (dart:core/uri.dart:1678:12)
E/flutter (11332): #6 DataServiceOneCall.getWeatherOneCall package:weather_app/data_service/data_service_onecall.dart:18
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我像这样重写了此代码,并且可以正常工作。
I rewrite this code like this and it works.
v斜线后会很小。
V after slash would be small.