Skip to content

Most visited

Recently visited

navigation

JSONException

public class JSONException
extends Exception

java.lang.Object
   ↳ java.lang.Throwable
     ↳ java.lang.Exception
       ↳ org.json.JSONException


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(String s)

Inherited methods

From class java.lang.Throwable
From class java.lang.Object

Public constructors

JSONException

Added in API level 1
JSONException (String s)

Parameters
s String
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.