douli1306
2019-03-26 22:47
浏览 567

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

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?

图片转代码服务由CSDN问答提供 功能建议

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

 执行热重启... 
 1.659ms中的重新启动的应用程序。
I / flutter(9594):加载xd en 
I / flutter(9594)  :异常:FormatException:意外的输入结束(在字符1处)
I / flutter(9594):
I / flutter(9594):^ 
I / flutter(9594):/ 0 
I / flutter(9594):error  :0 
   
 
 

我的json可以在这里找到: link

但是在此链接当我尝试解析json中的数据时它起作用,并且两个json看起来都相同。 (在这一个我无法访问PHP文件)

我像往常一样进行json打印,如下所示:

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

这有什么技巧/黑客吗? 我错过了什么吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dopq87915 2019-03-28 12:59
    已采纳

    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.

    打赏 评论

相关推荐 更多相似问题