Flutter 未处理的异常:将对象转换为可编码对象失败:“ApiResponse”实例

问题描述 投票:0回答:1

成功进行 api 调用后出现卡盘错误。以前是没问题的。但是突然chucker库出现了json编码问题。

I/flutter (18923): Failed to parse JSON: FormatException: Unexpected character (at character 2)
I/flutter (18923): {content-type: application/json, cookie: null, content-length: 876}
I/flutter (18923):  ^
I/flutter (18923): 
I/flutter (18923): Failed to parse JSON: FormatException: Unexpected character (at character 2)
I/flutter (18923): {content-type: application/json, Authorization: Bearer f8896cc1adaf864a88d7...
I/flutter (18923):  ^
I/flutter (18923): 
E/flutter (18923): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'ApiResponse'
E/flutter (18923): #0      _JsonStringifier.writeObject (dart:convert/json.dart:793:7)
E/flutter (18923): #1      _JsonStringifier.writeList (dart:convert/json.dart:844:9)
E/flutter (18923): #2      _JsonStringifier.writeJsonValue (dart:convert/json.dart:823:7)
E/flutter (18923): #3      _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
E/flutter (18923): #4      _JsonStringStringifier.printOn (dart:convert/json.dart:982:17)
E/flutter (18923): #5      _JsonStringStringifier.stringify (dart:convert/json.dart:967:5)
E/flutter (18923): #6      JsonEncoder.convert (dart:convert/json.dart:345:30)
E/flutter (18923): #7      JsonCodec.encode (dart:convert/json.dart:231:45)
E/flutter (18923): #8      jsonEncode (dart:convert/json.dart:114:10)
E/flutter (18923): #9      SharedPreferencesManager.addApiResponse (package:chucker_flutter/src/helpers/shared_preferences_manager.dart:45:7)
E/flutter (18923): <asynchronous suspension>
E/flutter (18923): #10     ChuckerDioInterceptor._saveResponse (package:chucker_flutter/src/interceptors/dio_interceptor.dart:79:5)
E/flutter (18923): <asynchronous suspension>
E/flutter (18923): #11     ChuckerDioInterceptor.onResponse (package:chucker_flutter/src/interceptors/dio_interceptor.dart:45:5)
E/flutter (18923): <asynchronous suspension>

pub.dev:

chucker_flutter: ^1.8.0
dio: ^5.7.0
dio_cookie_manager: ^3.1.1
cookie_jar: ^4.0.8
shared_preferences: ^2.3.2

我已经在 dio_manager.dart 中添加了这个:

Dio().interceptors.add(ChuckerDioInterceptor());

app.dart 中的这个:

navigatorObservers: [ChuckerFlutter.navigatorObserver],

我尝试禁用 Chucker 库,一切正常。但我想要用 chucker 库来调试。

flutter dart dio chucker
1个回答
0
投票

添加标题为 “内容类型”:“application/json”

© www.soinside.com 2019 - 2024. All rights reserved.