Stay organized with collections
Save and categorize content based on your preferences.
JSONException
open class JSONException : Exception
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);
}
}
Summary
Public constructors
JSONException
JSONException(s: String!)
JSONException
JSONException(cause: Throwable!)
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-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 2025-02-10 UTC."],[],[],null,["# JSONException\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nJSONException\n=============\n\n```\nopen class JSONException : Exception\n```\n\n|---|---|---|-----------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||||\n| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html) |||\n| | ↳ | [java.lang.Exception](../../java/lang/Exception.html#) ||\n| | | ↳ | [org.json.JSONException](#) |\n\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](../../java/lang/Double.html#isNaN()) or [infinities](../../java/lang/Double.html#isInfinite()).\n- Lookups using an out of range index or nonexistent name\n- Type mismatches on lookups\n\n\u003cbr /\u003e\n\nAlthough this is a checked exception, it is rarely recoverable. Most callers should simply wrap this exception in an unchecked exception and rethrow: \n\n```kotlin\npublic JSONArray toJSONObject() {\n try {\n JSONObject result = new JSONObject();\n ...\n } catch (JSONException e) {\n throw new RuntimeException(e);\n }\n }\n```\n\nSummary\n-------\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [JSONException](#JSONException(kotlin.String))`(`s:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` \u003cbr /\u003e |\n| [JSONException](#JSONException(kotlin.String,%20kotlin.Throwable))`(`message:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `cause:` `[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)!`)` \u003cbr /\u003e |\n| [JSONException](#JSONException(kotlin.Throwable))`(`cause:` `[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)!`)` \u003cbr /\u003e |\n\nPublic constructors\n-------------------\n\n### JSONException\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nJSONException(s: String!)\n``` \n\n### JSONException\n\nAdded in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nJSONException(\n message: String!, \n cause: Throwable!)\n``` \n\n### JSONException\n\nAdded in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nJSONException(cause: Throwable!)\n```"]]