http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx
这个网站上有几个服务,我现在不知道如何根据url获取城市ID
大虾们请帮帮忙
我现在在做天气预报的东西,目前只能根据城市ID获取天气预报,我想下一步直接根据城市名称得到天气预报
下面是根据城市ID获取天气预报的代码 private static List<String> getWeather(int cityCode) {
List<String> weatherList = new ArrayList<String>();
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getInputStream(WEATHER_QUERY_URL + cityCode);
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("string");
int len = nl.getLength();
for(int i = 0; i < len; i++) {
Node n = nl.item(i);
String weather = n.getFirstChild().getNodeValue();
weatherList.add(weather);
}
is.close();
} catch(Exception e) {
e.printStackTrace();
}
return weatherList;
}下面是已知URL
private static String SERVICES_HOST = "www.webxml.com.cn"; //web services主机URL
private static String WEATHER_SERVICES_URL = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/"; //web services天气服务URL
private static String WEATHER_QUERY_URL = WEATHER_SERVICES_URL + "getWeather?theUserID=&theCityCode="; //查询条件
private static String GET_CITY_CODE = WEATHER_SERVICES_URL + "getSupportCityString?theRegionCode=";
private static String GET_PROVINCE_CODE = WEATHER_SERVICES_URL + "getRegionProvince";
现在最需要怎么根据城市名称获取城市ID?请各位高手们帮帮,呵呵呵(小弟分暂时不多了,全部献上,但等新分来了肯定会加分),呵呵
这个网站上有几个服务,我现在不知道如何根据url获取城市ID
大虾们请帮帮忙
我现在在做天气预报的东西,目前只能根据城市ID获取天气预报,我想下一步直接根据城市名称得到天气预报
下面是根据城市ID获取天气预报的代码 private static List<String> getWeather(int cityCode) {
List<String> weatherList = new ArrayList<String>();
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getInputStream(WEATHER_QUERY_URL + cityCode);
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("string");
int len = nl.getLength();
for(int i = 0; i < len; i++) {
Node n = nl.item(i);
String weather = n.getFirstChild().getNodeValue();
weatherList.add(weather);
}
is.close();
} catch(Exception e) {
e.printStackTrace();
}
return weatherList;
}下面是已知URL
private static String SERVICES_HOST = "www.webxml.com.cn"; //web services主机URL
private static String WEATHER_SERVICES_URL = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/"; //web services天气服务URL
private static String WEATHER_QUERY_URL = WEATHER_SERVICES_URL + "getWeather?theUserID=&theCityCode="; //查询条件
private static String GET_CITY_CODE = WEATHER_SERVICES_URL + "getSupportCityString?theRegionCode=";
private static String GET_PROVINCE_CODE = WEATHER_SERVICES_URL + "getRegionProvince";
现在最需要怎么根据城市名称获取城市ID?请各位高手们帮帮,呵呵呵(小弟分暂时不多了,全部献上,但等新分来了肯定会加分),呵呵
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货