Google的Json Parsing Gson库:JsonElement和JsonObject有什么区别? [英] Google's Json Parsing Gson library: What's the difference between JsonElement and JsonObject?

查看:623
本文介绍了Google的Json Parsing Gson库:JsonElement和JsonObject有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public abstract class JsonElement extends Object 

一个表示Json元素的类.它可以是JsonObject,JsonArray,JsonPrimitive或JsonNull.

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 

一个类,表示Json中的对象类型.一个对象由名称-值对组成,其中名称是字符串,而值是任何其他类型的JsonElement.这允许创建JsonElements树.该对象的成员元素按添加的顺序进行维护.

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.

是的,谷歌!

不要理会这个问题.

推荐答案

JsonElement包含JSON中所有有效类型的通用代码:

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

  • JsonObject
  • JsonArray
  • JsonPrimitive(字符串,数字,布尔值)
  • JsonNull

这使您可以编写一个使用JsonElement的方法,该方法可与以上任何类型一起使用.

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

这篇关于Google的Json Parsing Gson库:JsonElement和JsonObject有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆