[英]Can I use JSONObject instead of HashMap in Java?
I am doing an application which has a server and web, native clients. 我正在做一个具有服务器和Web本机客户端的应用程序。 Whenever a request comes from any of the client server should do the following: 每当来自任何客户端服务器的请求都应执行以下操作:
Generally I fetch the data and put it into an HashMap
and pass it to the JSP page. 通常,我获取数据并将其放入HashMap
并将其传递到JSP页面。 But for native requests I am planning to return the data in json format. 但是对于本机请求,我计划以json格式返回数据。 Here my doubt is instead of having data in different objects( HashMap
and JSONObject
), can I use the JSONObject
for both purposes?. 在这里我的疑问是不是可以将数据存储在不同的对象( HashMap
和JSONObject
)中,我可以同时使用JSONObject
吗? Will there be any performance implications when I use JSONObject
instead of HashMap
?. 当我使用JSONObject
代替HashMap
时,会对性能产生影响吗?
There will be not that much differentce, because most implementations of JSON are backed by maps. 差别不会太大,因为大多数JSON实现都由地图支持。 Better solution ( from JSP point of view ) would be using java beans, and convert your JSON / other data source to objects using some databinding solution 更好的解决方案(从JSP角度来看)将使用Java Bean,并使用某些数据绑定解决方案将JSON /其他数据源转换为对象
从软件工程的角度来看,不应在其他层(例如示例中的持久性层)中使用特定于视图的数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.