[英]Returning JSON Object from Struts2 Action Giving Empty Data
在行動:
//Declaration
JSONObject jObj1 = null;
public JSONObject getjObj1() {
return jObj1;
}
public void setjObj1(JSONObject jObj1) {
this.jObj1 = jObj1;
}
//In Action method
String jsong="{\"cid\":232}";
jObj1 = new JSONObject(jsong);
return Action.SUCCESS
Struts Cfg文件 :
<action name="jsonAction" class="jsonAction" method="getJson">
<result type="json" name="success">
<param name="root">jObj1</param>
</result>
</action>
當我在JSP控制台中看到時,我得到空的結果
哪里出錯了? 謝謝。
你太復雜了:)
Struts2-JSON-Plugin將為您在JSON中序列化您的Action對象 ,因此您不需要(並且這是一個錯誤)自己編碼它們。
然后,保持您的代碼和配置不變,只需將操作更改為:
//Declaration
Map<String,Integer> jObj1 = null;
/* Getter and Setter */
//In Action method
jObj1 = new HashMap<String,Integer>();
jObj1.put("cid",232);
return Action.SUCCESS
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.