<< Chapter < Page Chapter >> Page >

Go back to Question 6

Answer 5

True. The JSONArray class provides two overloaded versions of the method named toJSONString . One is an instance method and the other is a static method. On a side note, this is also true of the class named JSONObject .

Go back to Question 5

Answer 4

False. The code in Listing 2 produces the screen output shown in Figure 4 . Unlike an object of the JSONObject class, an object of the JSONArray class is an ordered list. By this we meanthat the user has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list) .

Go back to Question 4

Answer 3

False. The code in Listing 1 produces the screen output with the errors shown in Figure 2 . The JSONArray class neither defines nor inherits a method named put .

Go back to Question 3

Answer 2

False. The JSONArray class extends the ArrayList class, which implements the List interface. Therefore, an object of the JSONArray class is a list and is not an array. For example, the elements in a JSONArray object cannot be accessed using the square bracket ([]) notation commonly associated with Java arrays. Instead, the elements are accessed using the add and get methods declared in the List interface and inherited from the ArrayList class.

Go back to Question 2

Answer 1

False. The JSONArray class extends the standard Java ArrayList class.

Go back to Question 1

Figures

This section contains Figures that may be referred to by one or more questions or answers.

Figure 1

[{"Name":"Tom"},{"Age":21},{"Student":true}]

Figure 2

Code01.java:22: error: cannot find symbol array.put(jsonObj01);^ symbol: method put(JSONObject)location: variable array of type JSONArray Code01.java:23: error: cannot find symbolarray.put(jsonObj02); ^symbol: method put(JSONObject) location: variable array of type JSONArrayCode01.java:24: error: cannot find symbol array.put(jsonObj03);^ symbol: method put(JSONObject)location: variable array of type JSONArray Note: Code01.java uses unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details. 3 errorsError: Could not find or load main class Code01 Press any key to continue . . .

Figure 3

[{"Name":"Tom"},{"Age":21},{"Student":true}]

Figure 4

[{"Name":"Tom"},{"Student":true},{"Age":21}]

Figure 5

[{"Name":"Tom"},{"Age":21},{"Student":true}] [{"Name":"Tom"},{"Age":21},{"Student":true}]

Figure 6

{"person":[{"Student":true},{"Age":21},{"Name":"Tom"}]}

Figure 7

[{"Student":true},{"Age":21},{"Name":"Tom"}]

Figure 8

{"person":[{"Name":"Tom"},{"Age":21},{"Name":"Tom"}]}

Listings

This section contains Listings that may be referred to by one or more questions or answers.

Listing 1

/************************************************ 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 Code01{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.put(jsonObj01); array.put(jsonObj02);array.put(jsonObj03); System.out.println(array.toJSONString());}//end main}//end class Code01

Questions & Answers

if three forces F1.f2 .f3 act at a point on a Cartesian plane in the daigram .....so if the question says write down the x and y components ..... I really don't understand
Syamthanda Reply
hey , can you please explain oxidation reaction & redox ?
Boitumelo Reply
hey , can you please explain oxidation reaction and redox ?
Boitumelo
for grade 12 or grade 11?
Sibulele
the value of V1 and V2
Tumelo Reply
advantages of electrons in a circuit
Rethabile Reply
we're do you find electromagnetism past papers
Ntombifuthi
what a normal force
Tholulwazi Reply
it is the force or component of the force that the surface exert on an object incontact with it and which acts perpendicular to the surface
Sihle
what is physics?
Petrus Reply
what is the half reaction of Potassium and chlorine
Anna Reply
how to calculate coefficient of static friction
Lisa Reply
how to calculate static friction
Lisa
How to calculate a current
Tumelo
how to calculate the magnitude of horizontal component of the applied force
Mogano
How to calculate force
Monambi
a structure of a thermocouple used to measure inner temperature
Anna Reply
a fixed gas of a mass is held at standard pressure temperature of 15 degrees Celsius .Calculate the temperature of the gas in Celsius if the pressure is changed to 2×10 to the power 4
Amahle Reply
How is energy being used in bonding?
Raymond Reply
what is acceleration
Syamthanda Reply
a rate of change in velocity of an object whith respect to time
Khuthadzo
how can we find the moment of torque of a circular object
Kidist
Acceleration is a rate of change in velocity.
Justice
t =r×f
Khuthadzo
how to calculate tension by substitution
Precious Reply
hi
Shongi
hi
Leago
use fnet method. how many obects are being calculated ?
Khuthadzo
khuthadzo hii
Hulisani
how to calculate acceleration and tension force
Lungile Reply
you use Fnet equals ma , newtoms second law formula
Masego
please help me with vectors in two dimensions
Mulaudzi Reply
how to calculate normal force
Mulaudzi
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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