Google's Json Parsing Gson library: What's the difference between JsonElement and JsonObject?

前端 未结 2 608
死守一世寂寞
死守一世寂寞 2021-02-03 19:23
public abstract class JsonElement extends Object 

A class representing an element of Json. It could either be a JsonObject, a JsonArray, a JsonPrimitiv

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 19:54

    JsonElement contains common code for all the valid types in JSON:

    • JsonObject
    • JsonArray
    • JsonPrimitive (string, number, boolean)
    • JsonNull

    This allows you a write a method that takes a JsonElement that works with any of the above types.

提交回复
热议问题