【问题标题】:how to wrap data from yahoo weather api?如何包装来自雅虎天气 api 的数据?
【发布时间】:2013-07-25 04:15:47
【问题描述】:

如何包装来自 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);

            }

    }

}

【问题讨论】:

    标签: java yahoo-weather-api


    【解决方案1】:

    在我的库中,我使用 JAXB 来编写雅虎天气响应。这里的代码:https://github.com/fedy2/yahoo-weather-java-api

    【讨论】:

      猜你喜欢
      • 2011-11-15
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多