Java Reference
In-Depth Information
XML data presentation
JSON data presentation
<gender>M</gender>
<contact>
"weight":78.6,
"gender":"M",
"contact":[
<address>Rue9632</address>
{"address":"Rue632"},
<phone>985-761-0</phone>
</contact>
</student>
{"phone":"985-761-0"}
]
}
}
Java API for JSON processing
The Java API for JSON processing defines an API to process ( parse , generate ,
transform , and query ) JSON documents by using either the streaming API or the
object model API.
The streaming API
The streaming API is for JSON as StAX API is for XML. In other words, the stream-
ing API is an event-based JSON parsing. It parses a JSON file sequentially and fires
an event whenever a it encounters a new tag in the stream (new value String, new
start of objet, end of objet, new start of an array …). The example that follows shows
us how to get contact information within the JSON data presented on the previous
page.
Example of JSON processing using the streaming API:
public String getStudentContact(String
jsonData) {
JsonParser parser = Json.createParser(new
StringReader(jsonData));
Search WWH ::




Custom Search