如何从雅虎天气api包装数据?
问题描述:
如何从雅虎天气API。我总结的数据有这样一个 代码中的城市可能会返回一个null
值和温度可能会返回。 请帮帮我。如何从雅虎天气api包装数据?
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);
}
}
}