ispiro
ispiro

Reputation: 27713

What is the difference between a JsonValue and a JsonObject?

What is the difference between a JsonValue and a JsonObject?

I see that JsonValue is the base class for JsonObject, JsonPrimitive and JsonArray. But aren't all of them simply JsonObjects?

Upvotes: 5

Views: 2213

Answers (1)

Sweeper
Sweeper

Reputation: 273805

JsonValue is , as you said, the base class of the three classes in questions. It is also abstract. This suggests that it represents something general. It's a general term.

JsonObject is a kind of JsonValue (since the former inherits from the latter). Which kind? This kind:

{ ... }

JsonArray is another kind of JsonValue. Which kind? This kind:

[ ... ]

JsonPrimitive is the third kind of JsonValue, and it represents the 3 other types of values you can have in JSON - Number, String, Boolean.

Upvotes: 7

Related Questions