Android com.google.gson.JsonSyntaxException
I am a java newbie and I need help resolving a JSON parsing error.
My code is as follows:
try {
//Read the server response and attempt to parse it as
JSON
Reader reader = new InputStreamReader(content);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
Gson gson = gsonBuilder.create();
List<JsonObject> posts = (List) gson.fromJson(reader,
JsonObject.class);
Log.e(TAG, "Results Size: " + posts.size());
// for(int i=0; i<posts.size(); i++){
// Log.e(TAG, "Checking: " + posts.get(i).title());
// }
content.close();
} catch (Exception ex) {
Log.e(TAG, "Failed to parse JSON due to: " + ex);
}
I get the following error from my posts.size() check:
Failed to parse JSON due to: com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY
at line 1 column 2
The JSON I am trying to read is at http://kylewbanks.com/rest/posts/ and
if successful my posts.size() should be returning 5.
Need help. I don't know JAVA well enough to figure this out ... and I've
been trying :-(
No comments:
Post a Comment