JsonObject vs JSONObject

huangapple go评论85阅读模式
英文:

JsonObject vs JSONObject

问题

我对Java库中的Json类有点困惑。
我至少能找到这3个,它们都似乎是Oracle的Json库:

为什么有这么多Oracle的json类?

英文:

I am a bit confused about Json Class in java libraries.
I could find these 3 at least and all seems Oracle Json Libraries

Why so many Oracle json class?

答案1

得分: 5

"我至少能找到这三个,它们似乎都是Oracle的Json库。

实际上,不止这些;请参阅 https://www.json.org/json-en.html 上的列表。许多不是Oracle类。确实 org.json.JSONObject 不是Oracle类。

为什么有这么多Oracle的json类?

历史原因。Oracle花了很长时间才在官方Java库中包含JSON支持。而在他们这么做之前,各种其他人/组织已经推出了自己的JSON库,并发展了自己的用户群。

(Oracle有两种JSON实现的原因是它们的设计目标明显不同。)

哪个是推荐的,为什么?

没有单一的推荐。这在很大程度上取决于你的应用程序对JSON支持的需求。你需要轻量级的东西吗?你需要与现有框架(例如Java EE或Java ME)兼容吗?你需要POJO“绑定”吗?流式解析器?"

英文:

> I could find these 3 at least and all seems Oracle Json Libraries

Actually, there are many more than that; see the list at https://www.json.org/json-en.html. Many are not Oracle classes. Indeed org.json.JSONObject is not an Oracle class.

> Why so many Oracle json class?

History. It took a long time for Oracle to include JSON support in the official Java libraries. And by the time that they did, various other people / organizations had produced their own offerings, and developed their own followings.

(The reason the Oracle have two JSON implementations is that their design goals are significantly different.)

> Which one is the recommended one and why?

There is no single recommendation. It very much depends on what your application requires in terms of JSON support. Do you want something light-weight? Do you need to fit in with an existing framework (e.g. Java EE or Java ME)? Do you need POJO "bindings"? Streaming parsers?

答案2

得分: 3

javax.jsonJSON-BJSON-P Java EE API 的一部分,用于 JSON 处理和数据绑定。通常在应用服务器(WildFly / Tomcat / ...)的上下文中使用。

com.oracle.json 是指 Java ME("Micro Edition")

org.json 只是另一个解析器,类似于 GSON。

你不会在 Java ME 环境之外使用 com.oracle.json,但你是否使用 javax.jsonorg.jsonGSONJackson 等取决于个人口味和要求。但大多数情况下,应用服务器已经包含了一个 JSON 解析器 - 对于 Wildfly,这个解析器在 JSON-B/P 比较晚才到达解析派对之前是 Jackson

英文:

You are mixing up a lot of things here.

javax.json is part of the JSON-B and JSON-P Java EE API - used for JSON processing and data binding. And used in context of an application server (WildFly / Tomcat / ...)

whereas com.oracle.json refers to Java ME ("Micro Edition").

and org.json is just another parser, like GSON.

You wouldn't use com.oracle.json outside of a Java ME environment, but whether you use javax.json, org.json, GSON, Jackson, ... is up to your personal taste and requirements. But mostly, the application server already contains a JSON parser - for Wildfly, this was Jackson until JSON-B/P arrived rather late to the parsing party.

huangapple
  • 本文由 发表于 2020年7月29日 23:45:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63157399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定