【问题标题】:How To return only array not json object in struts2如何在struts2中只返回数组而不是json对象
【发布时间】:2016-01-23 04:30:27
【问题描述】:
<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"}]

【问题讨论】:

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


    【解决方案1】:

    你需要指定你想要被序列化的对象为the root object

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2013-09-23
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多