flutter 网络请求 application/json ch
2019-12-07 本文已影响0人
氵木子剑
初学flutter,在仿某app,获取该app新闻列表数据,但是不幸的是又又又报错了;
E/flutter ( 9416): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Error on line 1, column 18: Invalid media type: expected no more input.
E/flutter ( 9416): ╷
E/flutter ( 9416): 1 │ application/json charset=utf-8
E/flutter ( 9416): │ ^
E/flutter ( 9416): ╵
E/flutter ( 9416): #0 wrapFormatException (package:http_parser/src/utils.dart:15:5)
E/flutter ( 9416): #1 new MediaType.parse (package:http_parser/src/media_type.dart:46:12)
E/flutter ( 9416): #2 _contentTypeForHeaders (package:http/src/response.dart:84:39)
E/flutter ( 9416): #3 _encodingForHeaders (package:http/src/response.dart:77:24)
初以为是因为自己headers参数,然而加了貌似也没啥卵用。
无独有偶看见一篇文章要解析返回的json string,必须要指定UTF8字符解析response才可以;
Utf8Codec().decode(response.bodyBytes)
将响应数据解析后,果然不报错!