Add type checking before casting parse() results to JSONArray/JSONObject.
When parse() returns an unexpected type (e.g., String for malformed input),
the code now throws a descriptive JSONException instead of ClassCastException.
This prevents unchecked exceptions from propagating to callers who only
expect JSONException from these methods.
Fixes#1034