最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

org.apache.struts2.json.JSONException 解决方法

旗下网站admin65浏览0评论

org.apache.struts2.json.JSONException 解决方法

org.apache.struts2.json.JSONException 解决方法

配置文件代码

<package name="dictionary_ajax_code" extends="json-default">

    <action name="DictionaryType_ADD_SUBMIT" method="addSubmit" 
        class="com.farm.core.dictionary.web.DictionaryTypeAction">
        <result type="json"></result>
    </action>

</package>

AJAX和后台交互返回json时 报如下异常:

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: 
org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter 
can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)

主要原因:struts会将action中定义的一些变量序列化转换成json格式,需要调用对象的一系列get方法,因为有对象无法被序列化所以报错

解决方法

  • 一:去掉getXXX()方法

  • 二:在getXXX()方法上用注释@JSON(serialize=false)

作者:itmyhome

发布评论

评论列表(0)

  1. 暂无评论