基本信息
源码名称:简单的天气预报小工具(Jason解析小实例)
源码大小:1.14M
文件格式:.zip
开发语言:Java
更新时间:2016-12-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍
简单的天气预报小工具(联网,Jason解析小实例)

new Thread() {
public void run() {
try {
//Log.i(Tag,"2...");
String Basepath = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=";
String City = et_City.getText().toString().trim();
if(TextUtils.isEmpty(City)) {
Toast.makeText(MainActivity.this, "对不起,名称不能为空!", 0).show();
}else {
String path = Basepath URLEncoder.encode(City);
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
int code = conn.getResponseCode();
if(code == 200) {
InputStream is = conn.getInputStream();
XmlPullParser praser = Xml.newPullParser();
praser.setInput(is, "UTF-8");
int type = praser.getEventType();

List<String> infos = new ArrayList<String>();
while(type!=XmlPullParser.END_DOCUMENT) {
if(type==XmlPullParser.START_TAG) {
if("string".equals(praser.getName())) {
//Log.i(Tag,"type:" type);
String str = praser.nextText();
infos.add(str);
}
}
type = praser.next();
}
Message msg = Message.obtain();
msg.obj = infos;
handler.sendMessage(msg);
}
}