Download presentation
Presentation is loading. Please wait.
1
JSON in Java JSON-P API (JSON Processing)
javax.json.* Unfortunately: not part of Java SE, but Java EE (7,8) JSON syntax definition:
2
Three models JSON-P Object model (similar to DOM for XML)
javax.json.JsonObject, javax.json.JsonArray, JSON-P Straming model (similar to StAX for XML) javax.json.stream.JsonParser, javax.json.JsonWriter JSON Binding (JSON-B similar to JAXB) (official only in EE8) javax.json.bind.Jsonb, javax.json.bind.JsonBuilder
3
Examples private String json = "{\"id\": , " + "\"title\": \"Fun with JSON-Processing\", " + "\"published\": true}"; JsonReader jsonReader = Json.createReader( new StringReader(json)); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close(); jsonObject.getInt("id") jsonObject.getString("title") jsonObject.getBoolean("published")
4
Examples JsonObject jsonObject = Json.createObjectBuilder() .add("id", ) .add("title", "Fun with JSON-Processing") .add("published", true) .build(); jsonObject.getInt("id") jsonObject.getString("title") jsonObject.getBoolean("published")
5
Further hints: JSON Binding API in a nutshell Jsonb intro
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.