简体   繁体   English

在动作调用中生成Struts 2 JSON输出

[英]Generate Struts 2 JSON Output within Action Call

I'm currently working on making an Struts 2 Action call with a JSON response - I'd like to have the response be cache-able, which means I need to get the JSON generated within the code before the call is made. 我目前正在使用JSON响应进行Struts 2 Action调用-我希望该响应是可缓存的,这意味着我需要在调用之前获取代码内生成的JSON。 Something like this, within and action's execute() method: 在action的execute()方法中是这样的:

String json = this.getJSONOutput();
JSONCacheUtils.cache(hash, json);

Is there any way to do this using the Struts 2 JSON library? 有什么方法可以使用Struts 2 JSON库执行此操作吗?

You can use Struts2 JSON plugin API to serialize object. 您可以使用Struts2 JSON插件API 序列化对象。 The same way JSONResult is doing when it's executed. 执行时与JSONResult相同。

String json = JSONUtil.serialize(rootObject, excludeProperties, includeProperties, ignoreHierarchy, enumAsBean, excludeNullProperties);

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

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