FormatException:输入的意外结束(在字符1处) [英] FormatException: Unexpected end of input (at character 1)

查看:716
本文介绍了FormatException:输入的意外结束(在字符1处)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从json解析数据,但是出了点问题. 终端控制台说:

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

可以在这里找到我的json:链接

My json can be found here: link

但是在这个链接上,当我尝试从json解析数据时,它可以工作,而且两个json看起来都一样. (在这一点上,我无权访问PHP文件)

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)

我像往常一样进行json打印,

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?

推荐答案

一直在努力解决同样的错误... 触发POST req有什么奇怪的地方,但是无论如何都抛出了异常.

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());

用于监视输出-将在今天晚上找出哪一个(可能是Map),并告知您.同时,请重新检查您的响应类型并解码-就像我的情况一样,它肯定有问题.

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.

这篇关于FormatException:输入的意外结束(在字符1处)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆