Dio: DioError [DioErrorType.DEFAULT]: type 'String' is not a subtype of type 'Map<String, dynamic>

Created on 24 Mar 2020  ·  4Comments  ·  Source: flutterchina/dio

遇到一个很神奇的问题,其它的接口都是好的,就这个json解析失败
DioMixin.assureResponse (package:dio/src/dio.dart:1138:9)
I/flutter (14318): #1 DioMixin._request. (package:dio/src/dio.dart:904:14)
I/flutter (14318): #2 _rootRunUnary (dart:async/zone.dart:1134:38)
I/flutter (14318): #3 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
I/flutter (14318): #4 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
I/flutter (14318): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
I/flutter (14318): #6 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
I/flutter (14318): #7 Future._complete (dart:async/future_impl.dart:514:7)
I/flutter (14318): #8 _SyncCompleter.complete (dart:async/future_impl.dart:53:12)
I/flutter (14318): #9 Future.any. (dart:async/future.dart:459:45)
I/flutter (14318): #10 _rootRunUnary (dart:async/zone.dart:1134:38)

stale

Most helpful comment

找到原因了.....原来服务器必须加上json类型的header QAQ
~
header( 'Content-Type:application/json;charset=utf-8 ');
~

All 4 comments

找到原因了.....原来服务器必须加上json类型的header QAQ
~
header( 'Content-Type:application/json;charset=utf-8 ');
~

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

╔ Body
I/flutter ( 6463): ║
I/flutter ( 6463): ║ {"status_code":"200","status":"true","data":{"id":"52","name":"jkj","linestatus":0}}
I/flutter ( 6463): ║
I/flutter ( 6463): ╚══════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 6463): DioError [DioErrorType.DEFAULT]: type 'String' is not a subtype of type 'Map'

找到原因了.....原来服务器必须加上json类型的header QAQ

header( 'Content-Type:application/json;charset=utf-8 ');

后台不修改的情况下,自己处理,需要decode成json格式:json.decode(response.data) 使用这个方式也可以

Was this page helpful?
0 / 5 - 0 ratings