引起:com.google.gson.TokenMgrError:第1行第1列的词汇错误。遇到:"<" (60),之后:""

时间:2014-05-27 15:40:14

标签: json gson android android-parser

在我的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)

示例回复: {&#34;的MCode&#34;:&#34; 123&#34;&#34; mobilesettings&#34; {&#34;移动&#34;:&#34; 07405123154&#34;&#34 ;电子邮件&#34;:&#34; rcb@rtc.com",&#34;电话&#34;:&#34; 0174465599&#34;&#34;超时&#34;:20,&# 34; MAIL_ADDRESS&#34;:&#34; abc.gmail.com&#34;&#34; mail_user&#34;:&#34; mail.user@gmail.com",&#34; mail_password&# 34;:&#34;密码&#34;&#34; task_state&#34;:0,&#34; force_task_reason&#34;:0,&#34; allow_free_task_reason&#34;:1,&#34; unsent_sync& #34;:10,&#34; booking_sync&#34;:240,&#34; default_scan_mode&#34;:0,&#34; gps_enabled&#34;:1,&#34; gps_poll_interval&#34;:5, &#34; minimum_gps_accuracy&#34;:100.0&#34; allow_blank_aborted_reason&#34;:假,&#34; allow_free_aborted_reason&#34;:真}&#34;工作人员&#34; {&#34; json_class&# 34;:&#34;工作人员&#34;&#34; staff_id&#34;:1234,&#34;标题&#34;:&#34;&#34;&#34; FNAME&#34 ;: &#34;抹布&#34;&#34; MNAME&#34;:&#34;&#34;&#34; SNAME&#34;:&#34;抹布&#34;&#34; LOCATION_ID& #34;:321,&#34;寻呼机&#34;:&#34;&#34;&#34;移动&#34;:&#34; 07444456789&#34;&#34;电子邮件&#34; :&#34; abc@def.com #&34;,&#34;网站&#34;:&#34;&#34;&#34; DOB&#34;:空,&#34; JOB_TITLE&#34;:&#34;&#34 ;,&#34; uid_ref&#34;:1,&#34; dt_stamp&#34;:&#34; 2月11日星期二13:13:44 +0000 2014&#34;,&#34; pin_no&#34;: &#34;&#34;,&#34; wroptions&#34;:0,&#34; dt_created&#34;:&#34; Wed Dec 04 16:13:08 +0000 2013&#34;,&# 34; user_created&#34;:1,&#34; pin_start&#34;:&#34; 1234&#34;&#34; pin_end&#34;:&#34; 1234&#34;&#34; payroll_report& #34;:&#34; Payroll.xml&#34;&#34; external_payroll_ref&#34;:&#34;&#34;&#34; payroll_export&#34;:&#34; Payroll.sql&# 34;,&#34;供应商&#34;:0,&#34; is_saved&#34;:1}}

1 个答案:

答案 0 :(得分:0)

我发现,在期待json响应时,我收到来自强制门户网站wifi的html响应,如BT热点或Virgin媒体热点。因此解析器失败并导致错误。