简体   繁体   English

未处理的异常:FormatException:意外的输入结束(在字符 1)

[英]Unhandled Exception: FormatException: Unexpected end of input (at character 1)

I am trying to parse following map using http in flutter我正在尝试在颤振中使用 http 解析以下地图

 Map<String, dynamic> map = {
      "studentID": "${widget.userId}".toString(),
      "gstNumber": "${widget.feesBloc?.gstNumberValue}" ?? "",
      "entityName": "${widget.feesBloc?.gstEntityValue}" ?? "",
      "paymentInfo": {
        "amount": "$tempAmount".toString(),
        "razorpay_payment_id": "$razorPaymentId" ?? "",
        "usedWB": "$_walletAmount"
      },
      "feeInfo": {
        "feeID": "${widget.feesData.feeID}".toString(),
        "type": "${widget.feesData.type}",
        "category": "${widget.feesData.category}".toString(),
        "feeCode": "${widget.feesData.feeCode}".toString(),
        "feeShortName": "${widget.feesData.feeShortName}" ?? "",
        "basicAMT": "${widget.feesData.basicAMT}".toString(),
        "dueDate": "${widget.feesData.dueDate}".toString(),
        "grandAMT": "${widget.feesData.grandAMT}",
        "status": "${widget.feesData.status}".toString(),
        "collectionID": "${widget.feesData.collectionID}".toString(),
        "dateStatus": "${widget.feesData.dateStatus}".toString(),
        "collectionDetailStatus": "-1",
        "schemeInfo": {
          "schemeID": "1",
          "schemeNo": "${widget.feesData.schemeInfo.schemeNo}",
          "schemeTxt": "a" ?? "",
          "schemeStatus": "${widget.feesData.schemeInfo.schemeStatus}"
        },
        "lateFeeInfo": {
          "lateDays": "${widget.feesData.lateFeeInfo.lateDays}",
          "lateFeePerDay":
              "${widget.feesData.lateFeeInfo.lateFeePerDay}".toString(),
          "lateFeeAMT": "${widget.feesData.lateFeeInfo.lateFeeAMT}"
        },
        "taxInfo": {
          "tax": "${widget.feesData.taxInfo.tax}".toString(),
          "taxAMT": "${widget.feesData.taxInfo.taxAMT}".toString(),
          "taxAddedAMT": "${widget.feesData.taxInfo.taxAddedAMT}"
        },
        "scholarshipInfo": {
          "scholarship":
              "${widget.feesData.scholarshipInfo.scholarship}".toString(),
          "scholarshipAMT": "${widget.feesData.scholarshipInfo.scholarshipAMT}"
        }
      }

Following is my api code以下是我的api代码

Map<String, String> headers = {
      'Content-type': 'application/json',
      'Accept': 'application/json',
    };

    final response = await http.post(FEE_PAYMENT_URL,
        headers: headers, body: json.encode(jsonMap));

I am getting status code as 200 but response.body is not returned anything so the decoding fails我得到的状态代码为 200 但response.body没有返回任何内容,因此解码失败

Following is the full error以下是完整错误

Unhandled Exception: FormatException: Unexpected end of input (at character 1)
E/flutter ( 8915): 
E/flutter ( 8915): ^
E/flutter ( 8915): 
E/flutter ( 8915): #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1392:5)
E/flutter ( 8915): #1      _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:510:7)
E/flutter ( 8915): #2      _parseJson (dart:convert-patch/convert_patch.dart:30:10)
E/flutter ( 8915): #3      JsonDecoder.convert (dart:convert/json.dart:493:36)
E/flutter ( 8915): #4      JsonCodec.decode (dart:convert/json.dart:151:41)
E/flutter ( 8915): #5      FeePaymentApiProvider.submitFeePayment (package:dice/resources/fee_payment/fee_payment_api_provider.dart:22:42)
E/flutter ( 8915): <asynchronous suspension>
E/flutter ( 8915): #6      FeePaymentRepository.submitFeePayment (package:dice/resources/fee_payment/fee_payment_repository.dart:14:48)
E/flutter ( 8915): <asynchronous suspension>
E/flutter ( 8915): #7      FeesBloc.submitFeePayment (package:dice/bloc/fees_bloc/fees_bloc.dart:54:40)
E/flutter ( 8915): <asynchronous suspension>
E/flutter ( 8915): #8      _PresentFeesListItemState._submitDataToServerAfterPaymentIsSuccessful (package:dice/screens/fees/present_fees/present_fees_list_item.dart:517:21)
E/flutter ( 8915): #9      _PresentFeesListItemState.calculateFees (package:dice/screens/fees/present_fees/present_fees_list_item.dart:202:9)
E/flutter ( 8915): #10     _PresentFeesListItemState.build.<anonymous closure>.<anonymous closure> (package:dice/screens/fees/present_fees/present_fees_list_item.dart:165:21)
E/flutter ( 8915): #11     _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 8915): #12     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8915): #13     _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter ( 8915): #14     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter ( 8915): #15     Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter ( 8915): #16     Future._complete (dart:async/future_impl.dart:473:7)
E/flutter ( 8915): #17     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter ( 8915): #18     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:28:18)
E/flutter ( 8915): #19     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)
E/flutter ( 8915): #20     checkInternetConnection (package:dice/helpers/check_internet_connection.dart)
E/flutter ( 8915): <asynchronous suspension>
E/flutter ( 8915): #21     _PresentFeesListItemState.build.<anonymous closure> (package:dice/screens/fees/present_fees/present_fees_list_item.dart:163:17)
E/flutter ( 8915): #22     _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter ( 8915): #23     _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter ( 8915): #24     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 8915): #25     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 8915): #26     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
E/flutter ( 8915): #27     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter ( 8915): #28     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter ( 8915): #29     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 8915): #30     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 8915): #31     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 8915): #32     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 8915): #33     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 8915): #34     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8915): #35     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 8915): #36     _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter ( 8915): #37     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter ( 8915): 

Any help would be appreciated.任何帮助,将不胜感激。 I went through following questions on stack but they were of no use.我在堆栈上经历了以下问题,但它们没有用。 I am passing complex map structure the right way to my api in dart, the api works fine on postman我在 dart 中以正确的方式将复杂的地图结构传递给我的 api,该 api 在邮递员上运行良好

The error should point out to the unexpected format that's being tried to be parsed FormatException: Unexpected end of input (at character 1) .该错误应指出正在尝试解析的意外格式FormatException: Unexpected end of input (at character 1) From the logs you've shared it seems to highlight an empty value.从您共享的日志中,它似乎突出显示了一个空值。 It's likely that the json you're parsing is empty.您解析的 json 很可能是空的。 You can add a checker before parsing to avoid this issue.您可以在解析之前添加检查器以避免此问题。

if(response.body.isNotEmpty){
  // Do something
  json.decode(response.body);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到未处理的异常:FormatException:输入意外结束(在字符 1 处)并且不知道为什么? - I'm getting Unhandled Exception: FormatException: Unexpected end of input (at character 1) and don't know why? FormatException:输入意外结束(在字符 1 处)^ - FormatException: Unexpected end of input (at character 1) ^ 错误:flutter/lib/ui/ui_dart_state.cc(209) 未处理的异常:FormatException:意外字符(字符 1)flutter - ERROR:flutter/lib/ui/ui_dart_state.cc(209) Unhandled Exception: FormatException: Unexpected character (at character 1) flutter Flutter [错误:flutter/lib/ui/ui_dart_state.cc(177)] 未处理异常:FormatException:意外字符(在字符 1) - Flutter [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 1) Flutter FormatException:意外字符(字符 1) - Flutter FormatException: Unexpected character (at character 1) Flutter Http 发布请求抛出未处理的异常:FormatException:无效的基数 10 数(在字符 1) - Flutter Http post request is throwing Unhandled Exception: FormatException: Invalid radix-10 number (at character 1) json.decode() 输入意外结束(在字符 1 处) - json.decode() Unexpected end of input (at character 1) Flutter http 客户端给出 FormatException: Unexpected character (at character 1)<!DOCTYPE html> - Flutter http client gives FormatException: Unexpected character (at character 1) <!DOCTYPE html> FormatException:意外字符(在字符 1 处),这是我在解码 json 格式时发生的错误 - FormatException: Unexpected character (at character 1), this is my error occur while decoding my json format Promise上的JSON输入意外结束 - Unexpected end of JSON input on Promise resolve
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM