java - 如何包装来自雅虎天气 api 的数据?

标签 java yahoo-weather-api

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

相关文章:

java - 在 LWUIT 组件上绘制 javax.microedition.lcdui.Graphics

Java:在输出流中多次写入带有新参数的同一对象

java - HSQLDB - 更改/删除加密 key

rss - 雅虎 加拿大 天气 RSS feed

PHP:Yahoo Weather Api 使用 file_get_content 获取空结果

java - 我如何让这个数组结束?

java - 尝试使用 PowerMock 模拟静态系统类会给出 VerifyError

android - 如何从 Yahoo Weather 获取 5 天天气预报

android - 如何获取当前位置的天气

javascript - 我的 xhr.onreadystatechange 函数在运行 if 代码之前运行 else 代码两次