This page is optimized for mobile devices, if you would prefer the desktop version just click here

22.10 Json0220r: review  (Page 4/4)

Listing 4

/******************************************************************** Copyright 2016 R.G.BaldwinTested with Java 8, Win 7, and json-simple-1.1.1.jar. ********************************************************************/import org.json.simple.JSONObject; import org.json.simple.JSONValue;class Code04 { public static void main(String[]args){ JSONObject jsonObj01 = new JSONObject();jsonObj01.put("name","Joe"); jsonObj01.put("age",21);String jsonString = jsonObj01.toJSONString();JSONObject jsonObj02 = (JSONObject)JSONValue.parse(jsonString); System.out.println(jsonObj02.get("name"));System.out.println(jsonObj02.get("age"));}//end main }//end class Code04

Listing 5

/******************************************************************** Copyright 2016 R.G.BaldwinTested with Java 8, Win 7, and json-simple-1.1.1.jar. ********************************************************************/import org.json.simple.JSONObject;import org.json.simple.parser.JSONParser; class Code05 {public static void main(String[] args){JSONObject jsonObj01 = new JSONObject(); jsonObj01.put("name","Joe");jsonObj01.put("age",21);String jsonString = jsonObj01.toJSONString(); JSONObject jsonObj02 = (JSONObject)JSONParser.parse(jsonString);System.out.println(jsonObj02.get("name")); System.out.println(jsonObj02.get("age"));}//end main}//end class Code05

Listing 6

/******************************************************************** Copyright 2016 R.G.BaldwinTested with Java 8, Win 7, and json-simple-1.1.1.jar. ********************************************************************/import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser;class Code06 { public static void main(String[]args){ JSONObject jsonObj01 = new JSONObject();jsonObj01.put("name","Joe"); jsonObj01.put("age",21);String jsonString = jsonObj01.toJSONString();JSONObject jsonObj02 = (JSONObject)(new JSONParser().parse(jsonString));System.out.println(jsonObj02.get("name")); System.out.println(jsonObj02.get("age"));}//end main}//end class Code06

Listing 7

/******************************************************************** Copyright 2016 R.G.BaldwinTested with Java 8, Win 7, and json-simple-1.1.1.jar. ********************************************************************/import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser;import org.json.simple.parser.ParseException; class Code07 {public static void main(String[] args) throws ParseException{JSONObject jsonObj01 = new JSONObject(); jsonObj01.put("name","Joe");jsonObj01.put("age",21);String jsonString = jsonObj01.toJSONString(); JSONObject jsonObj02 =(JSONObject)(new JSONParser().parse(jsonString)); System.out.println(jsonObj02.get("name"));System.out.println(jsonObj02.get("age"));}//end main }//end class Code07

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Json0220R: Review
  • File: Json0220R.htm
  • Published: 06/04/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-

<< Chapter < Page Page > Chapter >>

Read also:

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.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.