如何在struts2中只返回数组而不是json对象

时间:2015-10-23 15:07:45

标签: java json struts2 struts2-json-plugin struts-action

<action name="commissioner_info" method="commissioner_info" class="foo.bar.AdminInfoAction">
    <result name="json" type="json">    
        <param name="includeProperties">
            commissioner_info\[\d+\]\.fname,
            commissioner_info\[\d+\]\.designation,        
            commissioner_info\[\d+\]\.pathlocation
        </param>
    </result>
</action>

以上代码给出结果:

{"commissioner_info":[{"designation":"IG1","fname":"BS  Bassi ","pathlocation":"http:\/\/103.231.125.106\/nesos\/imagerepresentatives\/151021104556Bhim.jpg"}]}

但我只想要数组而不是json对象,比如

[{"designation":"IG1","fname":"BS  Bassi ","pathlocation":"http:\/\/103.231.125.106\/nesos\/imagerepresentatives\/151021104556Bhim.jpg"}]

1 个答案:

答案 0 :(得分:2)

您需要将要序列化的对象指定为 the root object

<result name="json" type="json">    
    <param name="root">
        commissioner_info
    </param>
</result>

否则整个动作将被序列化。 Read more here