我正在创建一个Web服务的客户端 - “www.webservicex.net/uszip.asmx”,它返回所有城市,并从那个状态返回邮政编码(我会将这些信息用于天气广播节目)。Web服务返回一个对象,我无法使用JAVA
ipSoap.getInfoByState()
返回一个对象GetInfoByStateResult(夹条氟利昂现在)。现在问题是我无法访问内容gibs了。 getContent()方法返回一个对象列表,但它没有方法让我得到我想要的数据(名称和拉链)。
如何从响应中获取城市和拉链的名称?
这里是我的代码:
public class Main {
public static void main(String[] args){
USZip ip = new USZip();
USZipSoap ipSoap = ip.getUSZipSoap();
GetInfoByStateResult gibs = ipSoap.getInfoByState("NJ"); //New York
List<Object> listOfCities = gibs.getContent();
/* problem here, getContent is always size 1, and i can't see what's inside in it. gibs.getIndex(0).toString returns: [NewDataSet: null].
*/
}
}
GetCityByResult是在底部
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="GetInfoByCityResult" minOccurs="0">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"getInfoByCityResult"
})
@XmlRootElement(name = "GetInfoByCityResponse")
public class GetInfoByCityResponse {
@XmlElement(name = "GetInfoByCityResult")
protected GetInfoByCityResponse.GetInfoByCityResult getInfoByCityResult;
/**
* Gets the value of the getInfoByCityResult property.
*
* @return
* possible object is
* {@link GetInfoByCityResponse.GetInfoByCityResult }
*
*/
public GetInfoByCityResponse.GetInfoByCityResult getGetInfoByCityResult() {
return getInfoByCityResult;
}
/**
* Sets the value of the getInfoByCityResult property.
*
* @param value
* allowed object is
* {@link GetInfoByCityResponse.GetInfoByCityResult }
*
*/
public void setGetInfoByCityResult(GetInfoByCityResponse.GetInfoByCityResult value) {
this.getInfoByCityResult = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
public static class GetInfoByCityResult {
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> content;
/**
* Gets the value of the content property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the content property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link String }
* {@link Object }
*
*
*/
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
}
return this.content;
}
}
}