繁体   English   中英

无法从服务器获取所有json响应

[英]Not able to fetch all json response from server

我想从服务器获取json响应,因为我正在使用以下代码

public class AtomAddressDetail implements java.io.Serializable {

    private Long id;
    private Place placeByStateId;
    private Atom atom;
    private Place placeByCountryId;
    private Place placeByCityId;
    private Place placeByStreetId;
    private Place placeByAreaId;
    private String houseno;
   //getter and setter
   }

public class Place implements java.io.Serializable {
    private Long id;
    private String name;
    private String about;
    //getter and setter
}

在行动

public class SettingAction extends ActionSupport {
 private long pageId; //getter and setter
private long id;  //getter and setter
 private List<AtomAddressDetail> atomAddressList;
    public String singleAddress() {
         setAtomAddressList(cdao.singleAddress(getId(), getPageId()));
         for (AtomAddressDetail a : getAtomAddressList()) {
                            System.out.println("Country " + a.getPlaceByCountryId().getId() + " " + a.getPlaceByCountryId().getName());
                            System.out.println("state " + a.getPlaceByStateId().getId() + " " + a.getPlaceByStateId().getName());
                            System.out.println("city " + a.getPlaceByCityId().getId() + " " + a.getPlaceByCityId().getName());
                             System.out.println("area " + a.getPlaceByAreaId().getId() + " " + a.getPlaceByAreaId().getName());
                            System.out.println("street " + a.getPlaceByStreetId().getId() + " " + a.getPlaceByStreetId().getName());
                        }
            }
         public List<AtomAddressDetail> getAtomAddressList() {
                return atomAddressList;
            }

            public void setAtomAddressList(List<AtomAddressDetail> atomAddressList) {
                this.atomAddressList = atomAddressList;
            }
 }

输出:

Country 2 India
state 3 asdf
city 4 sdfsd
area 5 www
street 6 sdfdsa f

struts.xml

<action name="SingleAddressDetail" class=".SettingAction" method="singleAddress">
            <result name="success" type="json">
                <param name="includeProperties">
                    ^atomAddressList\[\d+\]\.id,
                    ^atomAddressList\[\d+\]\.houseno,
                    ^atomAddressList\[\d+\]\.placeByAreaId.id,
                    ^atomAddressList\[\d+\]\.placeByAreaId.name,
                    ^atomAddressList\[\d+\]\.placeByCityId.id,
                    ^atomAddressList\[\d+\]\.placeByCityId.name,
                    ^atomAddressList\[\d+\]\.placeByStateId.id,
                    ^atomAddressList\[\d+\]\.placeByStateId.name,
                    ^atomAddressList\[\d+\]\.placeByCountryId.id,
                    ^atomAddressList\[\d+\]\.placeByCountryId.name
                </param>
                <param name="excludeNullProperties">true</param>
                <param name="root">
                    #action
                </param>
            </result>
            <result name="input" type="json"/>
            <result name="login" type="json"></result>
        </action> 

在JSP中

{"atomAddressList":[{"houseno":"sadf sadf ","id":1}]}

问题是在JSP页面中,我仅获得两个filds值,但我想获取struts.xml的操作中指定的所有值。

如前所述,值在操作中可以正确打印,但是可以在JSP中访问,例如alert(data.atomAddressList[0].placeByCountryId.id); 它显示

error:Uncaught TypeError: Cannot read property 'id' of undefined

您没有在json结果中包含某些属性,因为它们对于每个属性都应该是有效的regex表达式。 句号应转义。

<param name="includeProperties">
    ^atomAddressList\[\d+\]\.id,
    ^atomAddressList\[\d+\]\.houseno,
    ^atomAddressList\[\d+\]\.placeByAreaId\.id,
    ^atomAddressList\[\d+\]\.placeByAreaId\.name,
    ^atomAddressList\[\d+\]\.placeByCityId\.id,
    ^atomAddressList\[\d+\]\.placeByCityId\.name,
    ^atomAddressList\[\d+\]\.placeByStateId\.id,
    ^atomAddressList\[\d+\]\.placeByStateId\.name,
    ^atomAddressList\[\d+\]\.placeByCountryId\.id,
    ^atomAddressList\[\d+\]\.placeByCountryId\.name
</param>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM