<< Chapter < Page Chapter >> Page >

What you can expect

This book will explain how to use the following classes:

  • JSONObject
  • JSONValue
  • JSONParser
  • JSONArray
  • ParseException

An investigation into the use of the other classes and interfaces will be left as "an exercise for the student" .

Run the program

I encourage you to copy the code from Listing 1 . Execute the code and confirm that you get the same results as those shown in Figure 1 . Experiment with the code, making changes, and observing the results of your changes. Make certain that youcan explain why your changes behave as they do.

Complete program listing

Listing 1 provides the source code for the program named Code.java .

Listing 1 . Program named Code.java. /******************************************************************** Copyright 2016, R.G.BaldwinEstablishes the position of each of the json-simple classes in the class hierarchy by getting and displaying the superclass of eachclass. Produces the following output:ItemList: class java.lang.Object JSONArray: class java.util.ArrayListJSONObject: class java.util.HashMap JSONParser: class java.lang.ObjectJSONValue: class java.lang.Object ParseException: class java.lang.ExceptionYytoken: class java.lang.Object Tested with Java 8, Windows 7, and json-simple-1.1.1.jar********************************************************************/ import org.json.simple.JSONObject;import org.json.simple.JSONArray; import org.json.simple.JSONValue;import org.json.simple.ItemList; import org.json.simple.JSONAware;import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException;import org.json.simple.parser.Yytoken; class Code{public static void main(String[] args){System.out.println("ItemList: " + new ItemList().getClass().getSuperclass());System.out.println("JSONArray: " + new JSONArray().getClass().getSuperclass());System.out.println("JSONObject: " + new JSONObject().getClass().getSuperclass());System.out.println("JSONParser: " + new JSONParser().getClass().getSuperclass());System.out.println("JSONValue: " + new JSONValue().getClass().getSuperclass());System.out.println("ParseException: " + new ParseException(ParseException.ERROR_UNEXPECTED_CHAR).getClass().getSuperclass()); System.out.println("Yytoken: " +new Yytoken(Yytoken.TYPE_COLON,":"). getClass().getSuperclass());}//end main }//end class code

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Json0210: Structure of the json-simple JavaLibrary
  • File: Json0210.htm
  • Published: 05/30/16
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask