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

时间:2019-08-13 08:28:07

标签: http flutter dart

我正试图在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}"
        }
      }

以下是我的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));

我得到的状态码为200,但是response.body未返回任何内容,因此解码失败

以下是完整错误

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): 

任何帮助将不胜感激。我在堆栈上经历了以下问题,但它们没有用。我正在以正确的方式将复杂的地图结构传递到dart中的api,该api在邮递员上可以正常工作

0 个答案:

没有答案