-
- All Superinterfaces:
- AutoCloseable, Closeable
public interface JsonReader extends Closeable
Reads a JSONobject
or anarray
structure from an input source.The class
Json
contains methods to create readers from input sources (InputStream
andReader
).The following example demonstrates how to read an empty JSON array from a string:
JsonReader jsonReader = Json.createReader(new StringReader("[]")); JsonArray array = jsonReader.readArray(); jsonReader.close();
The class
JsonReaderFactory
also contains methods to createJsonReader
instances. A factory instance can be used to create multiple reader instances with the same configuration. This the preferred way to create multiple instances. A sample usage is shown in the following example:JsonReaderFactory factory = Json.createReaderFactory(config); JsonReader reader1 = factory.createReader(...); JsonReader reader2 = factory.createReader(...);
- Author:
- Jitendra Kotamraju
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void
close()
Closes this reader and frees any resources associated with the reader.JsonStructure
read()
Returns a JSON array or object that is represented in the input source.JsonArray
readArray()
Returns a JSON array that is represented in the input source.JsonObject
readObject()
Returns a JSON object that is represented in the input source.
-
-
-
Method Detail
-
read
JsonStructure read()
Returns a JSON array or object that is represented in the input source. This method needs to be called only once for a reader instance.- Returns:
- a JSON object or array
- Throws:
JsonException
- if a JSON object or array cannot be created due to i/o error (IOException would be cause of JsonException)JsonParsingException
- if a JSON object or array cannot be created due to incorrect representationIllegalStateException
- if read, readObject, readArray or close method is already called
-
readObject
JsonObject readObject()
Returns a JSON object that is represented in the input source. This method needs to be called only once for a reader instance.- Returns:
- a JSON object
- Throws:
JsonException
- if a JSON object cannot be created due to i/o error (IOException would be cause of JsonException)JsonParsingException
- if a JSON object cannot be created due to incorrect representationIllegalStateException
- if read, readObject, readArray or close method is already called
-
readArray
JsonArray readArray()
Returns a JSON array that is represented in the input source. This method needs to be called only once for a reader instance.- Returns:
- a JSON array
- Throws:
JsonException
- if a JSON array cannot be created due to i/o error (IOException would be cause of JsonException)JsonParsingException
- if a JSON array cannot be created due to incorrect representationIllegalStateException
- if read, readObject, readArray or close method is already called
-
close
void close()
Closes this reader and frees any resources associated with the reader. This method closes the underlying input source.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
JsonException
- if an i/o error occurs (IOException would be cause of JsonException)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 17:18:00 Cette version de la page est en cache (à la date du 21/08/2025 17:18:00) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/json/JsonReader.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.