org.json unreported exception while creating a JSONObject

constructor declares to throw org.json.JSONException so you must handle it (catch & handle or rethrow to let caller handle it)


Catch your Exception by creating try and catch:

try {
    JSONObject jsonObj = new JSONObject("{\"count\":3939,\"has_more\":true,\"map_location\":{\"lat\":0.60996950000000183,\"lon\":-27.568517000000003,\"panoramio_zoom\":16},\"photos\":[{\"height\":375,}]}");          
    System.out.println(jsonObj);
} catch (JSONException e) {
    //some exception handler code.
}  

Or either throws your exception to caller method:

public String yourMethod(String jsonString) throws JSONException  

Tags:

Java

Json