在我的android应用程序中,我面临一个非常奇怪的错误,无法进入它的根。进行网络调用并解析JSON响应。但是应用程序崩溃了,我收到以下错误:
随机发生,无法重现错误。如果以前遇到过这种情况的人能告诉我什么可能引发这次崩盘,那就太方便了。
com.google.gson.JsonParseException: Failed parsing JSON source: java.io.StringReader@40e13578 to Json
at com.google.gson.JsonParser.parse(JsonParser.java:57)
at com.google.gson.Gson.fromJson(Gson.java:443)
at com.google.gson.Gson.fromJson(Gson.java:396)
at com.google.gson.Gson.fromJson(Gson.java:372)
at com.xyz.getStaffFromJson(JsonUtils.java:201)
at com.xyz.getMyDetails(WebAPI.java:666)
at com.xyz.OptimisedSyncService.onHandleIntent(OptimisedSyncService.java:147)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: com.google.gson.TokenMgrError: Lexical error at line 1, column 1. Encountered: "<" (60), after : ""
at com.google.gson.JsonParserJavaccTokenManager.getNextToken(JsonParserJavaccTokenManager.java:1168)
at com.google.gson.JsonParserJavacc.jj_ntk(JsonParserJavacc.java:635)
at com.google.gson.JsonParserJavacc.parse(JsonParserJavacc.java:10)
at com.google.gson.JsonParser.parse(JsonParser.java:54)
... 10 more
com.google.gson.TokenMgrError: Lexical error at line 1, column 1. Encountered: "<" (60), after : ""
at com.google.gson.JsonParserJavaccTokenManager.getNextToken(JsonParserJavaccTokenManager.java:1168)
at com.google.gson.JsonParserJavacc.jj_ntk(JsonParserJavacc.java:635)
at com.google.gson.JsonParserJavacc.parse(JsonParserJavacc.java:10)
at com.google.gson.JsonParser.parse(JsonParser.java:54)
at com.google.gson.Gson.fromJson(Gson.java:443)
at com.google.gson.Gson.fromJson(Gson.java:396)
at com.google.gson.Gson.fromJson(Gson.java:372)
at com.xyz.getStaffFromJson(JsonUtils.java:201)
at com.xyz.getMyDetails(WebrosterAPI.java:666)
at com.xyz.OptimisedSyncService.onHandleIntent(OptimisedSyncService.java:147)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.os.HandlerThread.run(HandlerThread.java:60)
样本回答:{" mcode ": " 123 ", " mobilesettings ":{"移动":"07405123154"、"电子邮件":"rcb@rtc.com"、"电话":"0174465599","超时":20,"mail_address":"abc.gmail.com","mail_user":"mail.user@gmail.com","mail_password":"密码"、"task_state":0,"force_task_reason":0,"allow_free_task_reason":1、"unsent_sync":10"booking_sync":240年,"default_scan_mode":0,"gps_enabled":1、"gps_poll_interval":5"minimum_gps_accuracy":100.0,"allow_blank_aborted_reason":假的,"allow_free_aborted_reason":真正的},"工作人员":{"json_class":"工作人员","staff_id":1234年,"标题":"、"帧":"抹布"、"mname":"、"sname":"抹布"、"location_id":321年,"寻呼机":"、"移动":"07444456789"、"电子邮件":"abc@def.com"、"网站":"、"强加于人":空,"job_title":"、"uid_ref":1、"dt_stamp":"星期二2014年2月11日13:13:44 + 0000"、"pin_no":"、"wroptions":0,"dt_created":"结婚2013年12月04 16:13:08 + 0000"、"user_created":1、"pin_start":"1234"、"pin_end":"1234"、"payroll_report":"Payroll.xml"、"external_payroll_ref":"、"payroll_export":"Payroll.sql"、"供应商":0,is_saved: 1}}
我发现,虽然期待json响应,我收到一个html响应从捕获门户wifi如BT热点或维珍媒体热点。因此解析器失败并导致错误。