What are the significant diffs between:
有什么重大区别:
org.json.JSONObject and javax.json.JsonObject?
Most importantly are they interchangeable from client to Webservice? ie. can I send JSONObject to Webservice and have the Webservice believe the type is JsonObject (and vice versa)?
最重要的是它们可以从客户端转换为Webservice吗?即。我可以将JSONObject发送到Webservice并让Web服务认为类型是JsonObject(反之亦然)?
(JSONObject found in the json-20080701.jar of ACRA)
(在ACRA的json-20080701.jar中找到JSONObject)
(JsonObject found in C:\glassfish4\glassfish\modules\javax.json.jar)
(在C:\ glassfish4 \ glassfish \ modules \ javax.json.jar中找到JsonObject)
1 个解决方案
#1
6
What are the significant diffs between
org.json.JSONObject
andjavax.json.JsonObject
?org.json.JSONObject和javax.json.JsonObject之间有什么重要差异?
-
javax.json.JsonObject
is included in Java EE 7 - javax.json.JsonObject包含在Java EE 7中
-
javax.json.JsonObject
is immutable - javax.json.JsonObject是不可变的
-
org.json.JSONObject
has siginificantly more convenience methods - org.json.JSONObject具有非常多的便利方法
Most importantly are they interchangeable from client to Webservice? ie. can I send JSONObject to Webservice and have the Webservice believe the type is JsonObject (and vice versa)?
最重要的是它们可以从客户端转换为Webservice吗?即。我可以将JSONObject发送到Webservice并让Web服务认为类型是JsonObject(反之亦然)?
Of course this should work. It is not the class instance which gets transferred to the webservice, but the JSON data, which is generated from the class instance. On the other side, the JSON data can be parsed back into any kind of object.
当然这应该有效。它不是传递给webservice的类实例,而是从类实例生成的JSON数据。另一方面,JSON数据可以解析回任何类型的对象。
Example:
例:
If you have a simple class named Person:
如果你有一个名为Person的简单类:
public class Person {
private String name = "Hans";
private int age = 26;
}
This could be transformed into JSON similar to: {"name":"Hans", "age":25}
这可以转换为JSON,类似于:{“name”:“Hans”,“age”:25}
The generated JSON string is sent to the webservice.
生成的JSON字符串将发送到Web服务。
Now, on the other end of your application, or in any other application, this JSON string can be parsed into any class, if you have an appropriate parser. You don't even need Java to parse it.
现在,在应用程序的另一端或任何其他应用程序中,如果您有适当的解析器,则可以将此JSON字符串解析为任何类。你甚至不需要Java来解析它。
#1
6
What are the significant diffs between
org.json.JSONObject
andjavax.json.JsonObject
?org.json.JSONObject和javax.json.JsonObject之间有什么重要差异?
-
javax.json.JsonObject
is included in Java EE 7 - javax.json.JsonObject包含在Java EE 7中
-
javax.json.JsonObject
is immutable - javax.json.JsonObject是不可变的
-
org.json.JSONObject
has siginificantly more convenience methods - org.json.JSONObject具有非常多的便利方法
Most importantly are they interchangeable from client to Webservice? ie. can I send JSONObject to Webservice and have the Webservice believe the type is JsonObject (and vice versa)?
最重要的是它们可以从客户端转换为Webservice吗?即。我可以将JSONObject发送到Webservice并让Web服务认为类型是JsonObject(反之亦然)?
Of course this should work. It is not the class instance which gets transferred to the webservice, but the JSON data, which is generated from the class instance. On the other side, the JSON data can be parsed back into any kind of object.
当然这应该有效。它不是传递给webservice的类实例,而是从类实例生成的JSON数据。另一方面,JSON数据可以解析回任何类型的对象。
Example:
例:
If you have a simple class named Person:
如果你有一个名为Person的简单类:
public class Person {
private String name = "Hans";
private int age = 26;
}
This could be transformed into JSON similar to: {"name":"Hans", "age":25}
这可以转换为JSON,类似于:{“name”:“Hans”,“age”:25}
The generated JSON string is sent to the webservice.
生成的JSON字符串将发送到Web服务。
Now, on the other end of your application, or in any other application, this JSON string can be parsed into any class, if you have an appropriate parser. You don't even need Java to parse it.
现在,在应用程序的另一端或任何其他应用程序中,如果您有适当的解析器,则可以将此JSON字符串解析为任何类。你甚至不需要Java来解析它。