FormatException: Unexpected end of input (at character 1)

8,026

been struggling wit the same error since yesterday... whats strange that POST req is fired, but the exception was thrown anyway..

in my case, the problem was one of the temporary functions returning the response:

//      Response registerResponse = await dio.post(Strings.USER_REGISTER_URL, data: requestBody, options: new Options(contentType: ContentType("application", "json")));


//      print(TAG + registerResponse.toString());
//      print(TAG + registerResponse.data.toString());
//      Map<String, dynamic> parsedregisterResponse = jsonDecode(registerResponse.data);
//      print(TAG + "response: " + parsedregisterResponse.toString());

used to monitor the output - will find out which one (probably Map) this evening and let u know. In the meantime recheck your response type and decoding -there must be something wrong with it just like in my case.

Share:
8,026
Pablo
Author by

Pablo

Updated on December 10, 2022

Comments

  • Pablo
    Pablo over 1 year

    I'm trying to parse data from json but something is wrong. Terminal console says:

    Performing hot restart...
    Restarted application in 1.659ms.
    I/flutter ( 9594): Load xd en
    I/flutter ( 9594): Exception: FormatException: Unexpected end of input (at character 1)
    I/flutter ( 9594):
    I/flutter ( 9594): ^
    I/flutter ( 9594): /0
    I/flutter ( 9594): error: 0
    

    My json can be found here: link

    But at this link it works when I try to parse data from json, and both json's looks same. ( at this one I do not have access to PHP file)

    I did json print as usually, like this:

    $myJson = ['op'=>true,'msg'=>'','data'=>['pages'=>3538,'page'=>(int)$stranica,'news'=>$api]];
            print_r(json_encode($myJson));
    

    Is there any trick/hack about this? Am I missing something?

  • sagarchavan
    sagarchavan about 4 years
    What's the issue? I am stuck with this.