Code example for JSONException

0
     * @param mode Defines comparison behavior 
     * @throws JSONException 
     */ 
    public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode)
            throws JSONException 
    { 
        Object expected = JSONParser.parseJSON(expectedStr);
        Object actual = JSONParser.parseJSON(actualStr);
        if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) {
            return compareJSON((JSONObject) expected, (JSONObject) actual, mode);
        } 
        else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) {
            return compareJSON((JSONArray)expected, (JSONArray)actual, mode);
        } 
        else if (expected instanceof JSONObject) {
            throw new IllegalArgumentException("Expected a JSON object, but passed in a JSON array.");
        } 
        else { 
            throw new IllegalArgumentException("Expected a JSON array, but passed in a JSON object.");
        } 
    }