JSONException
Stay organized with collections
Save and categorize content based on your preferences.
Thrown to indicate a problem with the JSON API. Such problems include:
- Attempts to parse or construct malformed documents
- Use of null as a name
- Use of numeric types not available to JSON, such as
NaNs
or infinities
.
- Lookups using an out of range index or nonexistent name
- Type mismatches on lookups
Although this is a checked exception, it is rarely recoverable. Most
callers should simply wrap this exception in an unchecked exception and
rethrow:
public JSONArray toJSONObject() {
try {
JSONObject result = new JSONObject();
...
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
Public Constructor Summary
Inherited Method Summary
From class
java.lang.Throwable
synchronized
final
void
|
addSuppressed(Throwable arg0)
|
synchronized
Throwable
|
fillInStackTrace()
|
synchronized
Throwable
|
getCause()
|
String
|
getLocalizedMessage()
|
String
|
getMessage()
|
StackTraceElement[]
|
getStackTrace()
|
synchronized
final
Throwable[]
|
getSuppressed()
|
synchronized
Throwable
|
initCause(Throwable arg0)
|
void
|
printStackTrace()
|
void
|
printStackTrace(PrintWriter arg0)
|
void
|
printStackTrace(PrintStream arg0)
|
void
|
setStackTrace(StackTraceElement[] arg0)
|
String
|
toString()
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Public Constructors
public
JSONException
(String s)
public
JSONException
(String message, Throwable cause)
public
JSONException
(Throwable cause)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eJSONException\u003c/code\u003e signals problems with the JSON API, such as malformed documents, invalid data types, or incorrect lookups.\u003c/p\u003e\n"],["\u003cp\u003eThough a checked exception, it's often wrapped in an unchecked exception (e.g., \u003ccode\u003eRuntimeException\u003c/code\u003e) for practical handling.\u003c/p\u003e\n"],["\u003cp\u003eIt provides constructors to detail the error with a message, a cause, or both.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eJSONException\u003c/code\u003e inherits methods from \u003ccode\u003eThrowable\u003c/code\u003e for stack traces and error information.\u003c/p\u003e\n"]]],[],null,["# JSONException\n\npublic class **JSONException** extends Exception \nThrown to indicate a problem with the JSON API. Such problems include:\n\n- Attempts to parse or construct malformed documents\n- Use of null as a name\n- Use of numeric types not available to JSON, such as [NaNs](../../../reference/java/lang/Double.html#isNaN()) or [infinities](../../../reference/java/lang/Double.html#isInfinite()).\n- Lookups using an out of range index or nonexistent name\n- Type mismatches on lookups\n\nAlthough this is a checked exception, it is rarely recoverable. Most\ncallers should simply wrap this exception in an unchecked exception and\nrethrow: \n\n```\n public JSONArray toJSONObject() {\n try {\n JSONObject result = new JSONObject();\n ...\n } catch (JSONException e) {\n throw new RuntimeException(e);\n }\n }\n```\n\n\u003cbr /\u003e\n\n### Public Constructor Summary\n\n|---|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [JSONException](../../../reference/org/json/JSONException.html#JSONException(java.lang.String))(String s) |\n| | [JSONException](../../../reference/org/json/JSONException.html#JSONException(java.lang.String,%20java.lang.Throwable))(String message, Throwable cause) |\n| | [JSONException](../../../reference/org/json/JSONException.html#JSONException(java.lang.Throwable))(Throwable cause) |\n\n### Inherited Method Summary\n\nFrom class java.lang.Throwable \n\n|----------------------------------|-------------------------------------------|\n| synchronized final void | addSuppressed(Throwable arg0) |\n| synchronized Throwable | fillInStackTrace() |\n| synchronized Throwable | getCause() |\n| String | getLocalizedMessage() |\n| String | getMessage() |\n| StackTraceElement\\[\\] | getStackTrace() |\n| synchronized final Throwable\\[\\] | getSuppressed() |\n| synchronized Throwable | initCause(Throwable arg0) |\n| void | printStackTrace() |\n| void | printStackTrace(PrintWriter arg0) |\n| void | printStackTrace(PrintStream arg0) |\n| void | setStackTrace(StackTraceElement\\[\\] arg0) |\n| String | toString() |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| Object | clone() |\n| boolean | equals(Object arg0) |\n| void | finalize() |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public\n**JSONException**\n(String s)\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| s | |\n|---|---|\n\n#### public\n**JSONException**\n(String message, Throwable cause)\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| message | |\n| cause | |\n|---------|---|\n\n#### public\n**JSONException**\n(Throwable cause)\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| cause | |\n|-------|---|"]]