<< Chapter < Page Chapter >> Page >

Listing 2

/************************************************ Copyright: R.G.Baldwin 2016Tested with Java 8, Windows 7, and json-simple-1.1.1.************************************************/ import org.json.simple.JSONObject;import org.json.simple.JSONArray; class Code02{public static void main(String[] args){JSONObject jsonObj01 = new JSONObject(); jsonObj01.put("Name","Tom");JSONObject jsonObj02 = new JSONObject(); jsonObj02.put("Age",21);JSONObject jsonObj03 = new JSONObject(); jsonObj03.put("Student",true);JSONArray array = new JSONArray();array.add(0,jsonObj01); array.add(1,jsonObj03);array.add(2,jsonObj02); System.out.println(array.toJSONString());}//end main}//end class Code02

Listing 3

/************************************************ Copyright: R.G.Baldwin 2016Tested with Java 8, Windows 7, and json-simple-1.1.1.************************************************/ import org.json.simple.JSONObject;import org.json.simple.JSONArray; class Code03{public static void main(String[] args){JSONObject jsonObj01 = new JSONObject(); jsonObj01.put("Name","Tom");JSONObject jsonObj02 = new JSONObject(); jsonObj02.put("Age",21);JSONObject jsonObj03 = new JSONObject(); jsonObj03.put("Student",true);JSONArray array = new JSONArray();array.add(jsonObj01); array.add(jsonObj02);array.add(jsonObj03); System.out.println(JSONArray.toJSONString(array));System.out.println(array.toJSONString());}//end main }//end class Code03

Listing 4

/************************************************ Copyright: R.G.Baldwin 2016Tested with Java 8, Windows 7, andjson-simple-1.1.1. ************************************************/import org.json.simple.JSONObject; import org.json.simple.JSONArray;class Code04{ public static void main(String[]args){ JSONObject jsonObj01 = new JSONObject();jsonObj01.put("Name","Tom"); JSONObject jsonObj02 = new JSONObject();jsonObj02.put("Age",21); JSONObject jsonObj03 = new JSONObject();jsonObj03.put("Student",true);JSONArray array = new JSONArray(); array.add(jsonObj03);array.add(jsonObj02); array.add(jsonObj01);JSONObject jsonObj04 = new JSONObject();jsonObj04.put("person",array);System.out.println(array.toJSONString());}//end main }//end class Code04

Listing 5

/************************************************ Copyright: R.G.Baldwin 2016Tested with Java 8, Windows 7, and json-simple-1.1.1.************************************************/ import org.json.simple.JSONObject;import org.json.simple.JSONArray; class Code05{public static void main(String[] args){JSONObject jsonObj01 = new JSONObject(); jsonObj01.put("Name","Tom");JSONObject jsonObj02 = new JSONObject(); jsonObj02.put("Age",21);JSONObject jsonObj03 = new JSONObject(); jsonObj03.put("Student",true);JSONArray array = new JSONArray();array.add(jsonObj01); array.add(jsonObj02);array.add(jsonObj01);JSONObject jsonObj04 = new JSONObject(); jsonObj04.put("person",array);System.out.println(jsonObj04.toJSONString());}//end main}//end class Code05

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Json0225R: Review
  • File: Json0225R.htm
  • Published: 06/05/16
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download aPDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, youshould be aware 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 ofthe module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale onAmazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If youpurchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made andpublished without my 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