Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何包装来自雅虎天气api的数据?_Java_Yahoo Weather Api - Fatal编程技术网

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

Java 如何包装来自雅虎天气api的数据?,java,yahoo-weather-api,Java,Yahoo Weather Api,如何包装来自雅虎天气API的数据 城市可能返回null值,温度可能返回0。 请帮帮我 public class Handalinxml extends DefaultHandler{ Xmldatacollected info=new Xmldatacollected(); public String getInformation() { return info.dataToString(); } @Override public

如何包装来自雅虎天气API的数据 城市可能返回
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天气响应。代码如下:

在我的库中,我使用JAXB来编写yahoo天气响应。代码如下: