简体   繁体   English

JsonObject 与 JSONObject

[英]JsonObject vs JSONObject

I am a bit confused about Json Class in java libraries.我对 java 库中的 Json Class 有点困惑。 I could find these 3 at least and all seems Oracle Json Libraries我至少可以找到这 3 个,而且似乎都是 Oracle Json 库

Why so many Oracle json class?为什么这么多 Oracle json class?

I could find these 3 at least and all seems Oracle Json Libraries我至少可以找到这 3 个,而且似乎都是 Oracle Json 库

Actually, there are many more than that;实际上,还有很多。 see the list at https://www.json.org/json-en.html .请参阅https://www.json.org/json-en.html的列表。 Many are not Oracle classes.许多不是 Oracle 类。 Indeed org.json.JSONObject is not an Oracle class.实际上org.json.JSONObject不是 Oracle class。

Why so many Oracle json class?为什么这么多 Oracle json class?

History.历史。 It took a long time for Oracle to include JSON support in the official Java libraries. Oracle 花了很长时间才在官方 Java 库中包含 JSON 支持。 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.) (Oracle 有两个 JSON 实现的原因是它们的设计目标明显不同。)

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.这在很大程度上取决于您的应用程序在 JSON 支持方面需要什么。 Do you want something light-weight?你想要一些轻量级的东西吗? Do you need to fit in with an existing framework (eg Java EE or Java ME)?您是否需要适应现有框架(例如 Java EE 或 Java ME)? Do you need POJO "bindings"?你需要 POJO“绑定”吗? Streaming parsers?流式解析器?

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. javax.jsonJSON-BJSON-P Java EE API 的一部分 - 用于 Z0ECD11C1D7A2D7A202 数据绑定和处理。 And used in context of an application server ( WildFly / Tomcat /...)并在应用程序服务器的上下文中使用( WildFly / Tomcat /...)

whereas com.oracle.json refers to Java ME ("Micro Edition") .com.oracle.json指的是ZD52387880E1EA22817A72D3759213.18 版

and org.json is just another parser, like GSON. org.json只是另一个解析器,例如 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. 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.但大多数情况下,应用程序服务器已经包含一个 JSON 解析器 - 对于Wildfly ,这是Jackson ,直到JSON-B/P到达解析方相当晚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM