Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

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

public abstract class JsonElement extends Object 

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

public final class JsonObject extends JsonElement 

A class representing an object type in Json. An object consists of name-value pairs where names are strings, and values are any other type of JsonElement. This allows for a creating a tree of JsonElements. The member elements of this object are maintained in order they were added.

Yay google!

Nevermind that question.

question from:https://stackoverflow.com/questions/10954815/googles-json-parsing-gson-library-whats-the-difference-between-jsonelement-an

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...