Monday, April 14, 2014

gson parsing Sina java.lang.IllegalStateException: Expected a name but was NUMBER


First, I wrote posted Json parsing, ADT error locating the position in red, weiboinfo is my definition of a class
JsonReader jsonReader = new JsonReader (new StringReader (jsonDate));
jsonReader.beginObject ();
/ / String tagName = jsonReader.nextName ();

if (jsonReader.nextName (). equals ("statuses")) {
jsonReader.beginArray ();
while (jsonReader.hasNext ()) {
jsonReader.beginObject ();
/ * Create a new class of micro-blog information * /

/ / While (jsonReader.hasNext ()) {

if (jsonReader.nextName (). equals ("created_at")) {
weiBoInfo.setTime (jsonReader.nextString ());
}
/ * Else * / if (jsonReader.nextName (). Equals ("idstr")) {
weiBoInfo.setArticleId (jsonReader.nextString ());
}
/ * else * / if (jsonReader.nextName (). equals ("text")) {
weiBoInfo.setContent (jsonReader.nextString ());

}
/ * Else * / if (jsonReader.nextName (). Equals ("user")) {
jsonReader.beginObject ();
/ / While (jsonReader.hasNext ()) {
if (jsonReader.nextName (). equals ("idstr")) {
weiBoInfo.setPublisherId ("" + jsonReader.nextString ());
}
/ * Else * / if (jsonReader.nextName (). Equals ("screen_name")) {
weiBoInfo.setPublisherName (jsonReader.nextString ());
}
/ * Else * / if (jsonReader.nextName (). Equals ("profile_image_url")) {
weiBoInfo.setPublisherIcon (jsonReader.nextString ());
}
/ * Else * / if (jsonReader.nextName (). Contains ("thumbnail_pic")) {
weiBoInfo.setHaveImage (true);
}

/ /} / / End while
jsonReader.endObject ();

weiBoInfos.add (weiBoInfo);

}

/ /} / / End while


} / / End while
jsonReader.endObject ();
} / / End if
jsonReader.endArray ();
jsonReader.endObject ();
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Solve it? The same error.

No comments:

Post a Comment