我正在使用gson来解析json,但我收到了以下消息。它发生了一次或另一次,但大多数情况下它解析正确。
09-17 16:58:18.190: W/System.err(16785): com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 9381
09-17 16:58:18.190: W/System.err(16785): at com.google.gson.internal.Streams.parse(Streams.java:54)
09-17 16:58:18.190: W/System.err(16785): at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:54)
09-17 16:58:18.195: W/System.err(16785): at com.google.gson.Gson.fromJson(Gson.java:805)
09-17 16:58:18.195: W/System.err(16785): at com.google.gson.Gson.fromJson(Gson.java:770)
09-17 16:58:18.195: W/System.err(16785): at com.google.gson.Gson.fromJson(Gson.java:719)
09-17 16:58:18.200: W/System.err(16785): at com.google.gson.Gson.fromJson(Gson.java:691)
09-17 16:58:18.200: W/System.err(16785): at com.codal.whatsee.http.HttpRequest.makeRequest(HttpRequest.java:155)
09-17 16:58:18.200: W/System.err(16785): at com.codal.whatsee.fragmentactivity.SearchFragmentActivity$SearchUserTask.doInBackground(SearchFragmentActivity.java:415)
09-17 16:58:18.200: W/System.err(16785): at com.codal.whatsee.fragmentactivity.SearchFragmentActivity$SearchUserTask.doInBackground(SearchFragmentActivity.java:1)
09-17 16:58:18.205: W/System.err(16785): at android.os.AsyncTask$2.call(AsyncTask.java:288)
09-17 16:58:18.205: W/System.err(16785): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-17 16:58:18.205: W/System.err(16785): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-17 16:58:18.205: W/System.err(16785): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-17 16:58:18.205: W/System.err(16785): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-17 16:58:18.205: W/System.err(16785): at java.lang.Thread.run(Thread.java:841)
09-17 16:58:18.205: W/System.err(16785): Caused by: java.io.EOFException: End of input at line 1 column 9381
09-17 16:58:18.215: W/System.err(16785): at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1413)
09-17 16:58:18.215: W/System.err(16785): at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:496)
09-17 16:58:18.215: W/System.err(16785): at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:416)
我的解析
公共类WSSearchPost实现了JsonSerializer,JsonDeserializer {
@Override
public ISearchPostView deserialize(JsonElement jsonElement, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
SearchPostView ws = new SearchPostView();
ws.setId( jsonElement.getAsJsonObject().get("id").getAsString() );
ws.setImage( jsonElement.getAsJsonObject().get("image").getAsString() );
ws.setData( jsonElement.getAsJsonObject().get("date").getAsString() );
ws.setText( jsonElement.getAsJsonObject().get("text").getAsString() );
ws.setUser( jsonElement.getAsJsonObject().get("user").getAsInt() );
ws.setNome( jsonElement.getAsJsonObject().get("name").getAsString() );
ws.setUserNome( jsonElement.getAsJsonObject().get("username").getAsString() );
ws.setPhoto( jsonElement.getAsJsonObject().get("photo").getAsString() );
ws.setLocation( jsonElement.getAsJsonObject().get("location").getAsString() );
ws.setRating( jsonElement.getAsJsonObject().get("rating").getAsString() );
ws.setMyRating( jsonElement.getAsJsonObject().get("myrating").getAsString() );
ws.setNumComments( jsonElement.getAsJsonObject().get("numcomments").getAsString() );
ws.setNumFollowers( jsonElement.getAsJsonObject().get("numfollowers").getAsString() );
ws.setNumFollowing( jsonElement.getAsJsonObject().get("numfollowing").getAsString() );
ws.setFollowing( jsonElement.getAsJsonObject().get("following").getAsString() );
return ws;
// return arg2.deserialize(jsonElement, ws.getClass());
}