繁体   English   中英

如何包装来自Yahoo Weather API的数据?

[英]how to wrap data from yahoo weather api?

如何包装Yahoo Weather API中的数据。我有这样的代码,其中city可能返回null值,而温度可能返回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来发送yahoo天气响应。 这里的代码: https : //github.com/fedy2/yahoo-weather-java-api

暂无
暂无

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

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