2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

What's the issue? I am stuck with this.
I recently had the same issue due to an empty reponse body (http code 204 NO CONTENT). I use the BuiltValue Dart package and have a static method for deserializing the http response. The error message suggests that something is wrong with the request itself, but in my case I had to leave out the deserialization step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.