2

Yahoo Weather 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);

            }

    }

}
4

1 に答える 1

0

私のライブラリでは、yahoo の天気応答を wrp するために JAXB を使用しました。ここにコード: https://github.com/fedy2/yahoo-weather-java-api

于 2013-07-24T20:15:47.033 に答える