I'm having problems converting JsonElement to string. I am using the getAsString () method call, but I keep getting an exception from the improper operation. I checked the get output that I am calling and it seems correct.
Here is my code, Sorry for the poor naming conventions:
JsonParser jp2 = new JsonParser();
JsonObject root2 = jp2.parse(getAllEventsResults.get_Response()).getAsJsonObject();
JsonArray items2 = root2.get("items").getAsJsonArray();
for(int i=0; i<items2.size(); i++){
JsonObject item = items2.get(i).getAsJsonObject();
System.out.println(item.get("start").getAsString());}
The weirdest part of this is that I am doing the same thing in the above code with this code:
JsonParser jp = new JsonParser();
JsonObject root = jp.parse(getAllCalendarsResults.get_Response()).getAsJsonObject();
JsonArray items = root.get("items").getAsJsonArray();
JsonObject firstItem = items.get(0).getAsJsonObject();
String firstCalId = firstItem.get("id").getAsString();
source
share