如何包装来自 Yahoo Weather API 的数据。我有这样的代码
其中 city 可能会返回一个 null
值,而 temperature 可能会返回 0。
请帮助我。
public class Handalinxml extends DefaultHandler{
Xmldatacollected info=new Xmldatacollected();
public String getInformation()
{
return info.dataToString();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if(localName.equals("yweather:location"))
{
String city=attributes.getValue("city");
info.setCity(city);
}
if(localName.equals("yweather:forecast"))
{
String t=attributes.getValue("high");
int temp=Integer.parseInt(t);
info.setTemp(temp);
}
}
}
最佳答案
在我的库中,我使用 JAXB 来生成雅虎天气响应。这里的代码:https://github.com/fedy2/yahoo-weather-java-api
关于java - 如何包装来自雅虎天气 api 的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12702762/