为什么可以';我是否使用org.json.JSONObject替换com.ibm.json.java.JSONObject?
我使用WebSphereV9beta(支持JAX-RS2.0)实现restful。我有以下代码为什么可以';我是否使用org.json.JSONObject替换com.ibm.json.java.JSONObject?,java,json,Java,Json,我使用WebSphereV9beta(支持JAX-RS2.0)实现restful。我有以下代码 @GET @Path("/getJson1") @Produces(MediaType.APPLICATION_JSON) public JSONObject getJSON1() { String input = "This is input"; String output = "This is output"; JSONObject outputJsonObj = new
@GET
@Path("/getJson1")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getJSON1() {
String input = "This is input";
String output = "This is output";
JSONObject outputJsonObj = new JSONObject();
outputJsonObj.put("input", input);
outputJsonObj.put("output", output);
return outputJsonObj;
}
如果我使用“import com.ibm.json.java.JSONObject”,它会正常运行。但是如果我使用“import org.json.JSONObject”来实现json。我犯了以下错误
[ERROR] Problem with writing the data, class org.json.JSONObject, ContentType: application/json
[WARNING] Interceptor for HelloResource1 has thrown exception, unwinding now
No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )
我认为org.json更一般,但为什么我不能在websphere上relace com.ibm.json?这是来自不同库的两个完全不同的类。你应该阅读相关文档,并确保使用正确的库来完成你想要完成的任务。为什么我不能用大锤代替煎锅,天哪?:)com.ibm.json.java.JSONObject嵌入在WebSphere中,因此我可以直接使用它。但我想让这个计划更具普遍性。所以我想使用org.json。我不认为它们是不同的类,因为它们应该支持JavaEE规范。因此,我认为它们是相互替代的。