From the course: JSON Processing with Java EE
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: JSON array object
From the course: JSON Processing with Java EE
Solution: JSON array object
- [Instructor] So, how did you find your first challenge? Well, that challenge had two parts. Write code that loads a file containing a JSON and array and parse it into an object. And secondly, to write an appropriate unit test. So, let's start with the code part. As you can see here, the code is very similar to the code we wrote in the load JSON object method. The only difference is the method we call on the read object. This method reads the JSON data as JSON array, rather than as JSON object. It is important to note that if the data in the file is not actually a JSON array, the parse will not be able to read it and will throw a JSON parsing exception. So, you have to be sure of the data format if you wish to use this method. Alternatively, if you're not sure of the data structure, you could use the read method. This method returns a JSON structure, which represents all JSON structures. And then use the get value type to determine its type. To see an example of this, take a look at…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction to the object model2m 44s
-
(Locked)
Create a model from a JSON string6m 48s
-
(Locked)
Create a model from a JSON file2m 48s
-
(Locked)
JSON builder API1m 24s
-
Build a JSON model8m 30s
-
(Locked)
How to traverse the model1m 36s
-
(Locked)
Traverse the JSON model6m 19s
-
(Locked)
Output the JSON model to a data stream3m 16s
-
(Locked)
Challenge: JSON array object30s
-
(Locked)
Solution: JSON array object1m 11s
-
(Locked)
Challenge: Write unit test27s
-
(Locked)
Solution: Write unit test23s
-
(Locked)
Challenge: Output JSON object to a file18s
-
(Locked)
Solution: Output JSON object to a file36s
-
(Locked)
-
-