異常形式:
Class org.apache.struts2.json.JSONWriter can not access a member of * 或是 Class com.googlecode.jsonplugin.JSONWriter can not access a member of class*
第一種是struct2.1.8與json結合時的異常,第二種是struct2.1.6與json結合的異常。
具體:
Class org.apache.struts2.json.JSONWriter can not access a member of class oracle.jdbc.driver.BaseResultSet with modifiers "public"
解釋:
不能把程序中的某種數據結構串行化成json格式。
原因:
struts2的action里面的數據轉換成json數據時,會將提供了get方法的屬性都串行化輸出JSON到客戶端。有的時候,很多屬性并不能串行化成json數據,比如這里的oracle.jdbc.driver.BaseResultSet。這時還進行強行轉換就會出現這樣的異常。
解決方法:
在不能串行化到json的屬性相應的get方法前加一條json標記 @JSON(serialize=false)。告訴json不需要轉化這個屬性。或者根本不寫這個get方法。
后記:
對于不需要在前臺輸出的json數據,也可以用同樣的方法進行處理,從而減少服務器和客戶端間交互的信息量。
可在需要在前臺輸出的屬性的get方法前加上@JSON(name="status")標識,從而為該屬性起了一個別名,在前臺就可以通過status作為屬性名來讀取其值。
posted on 2011-08-02 17:01
Ke 閱讀(987)
評論(0) 編輯 收藏 所屬分類:
struts 2