美文网首页
flutter 网络请求 application/json ch

flutter 网络请求 application/json ch

作者: 氵木子剑 | 来源:发表于2019-12-07 10:14 被阅读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)
    

    将响应数据解析后,果然不报错!

    相关文章

      网友评论

          本文标题:flutter 网络请求 application/json ch

          本文链接:https://www.haomeiwen.com/subject/evaygctx.html