从服务器上请求json数据,并解析json数据
来源:互联网 发布:图片表格识别软件 编辑:程序博客网 时间:2024/06/05 21:05
private class WeatherThread extends Thread {
private WeatherInfo weather = null;
WeatherThread() {
weather = new WeatherInfo();
}
public void run() {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet get = new HttpGet("http://m.weather.com.cn/data/101270101.html");
HttpResponse response = null;
response = httpclient.execute(get);
if (response == null
|| response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return;
}
if (parse_http_response(response, weather) == false) {
return;
}}
}
private boolean parse_http_response(HttpResponse response, WeatherInfo info) {
HttpEntity entity = response.getEntity();
BufferedReader br = null;
StringBuffer sb = new StringBuffer(1024);
String result = null;
br = new BufferedReader(new InputStreamReader(entity.getContent()),
1024);
result = br.readLine();
while (result != null) {
sb.append(result);
result = br.readLine();
}
JSONObject json = null;
JSONObject wther = null;
json = new JSONObject(sb.toString());
wther = json.getJSONObject("weatherinfo");
if (wther != null) {
info.date = wther.getString("date_y");
info.temp_high = wther.getString("temp1");
info.weather = wther.getString("weather1");
info.wind = wther.getString("wind1");
info.img_title1 = wther.getString("img_title1");
info.img_title2 = wther.getString("img_title2");
if (weather_icon.containsKey(info.img_title1)) {
Integer resid = weather_icon.get(info.img_title1);
info.res_id = resid.intValue();
} else {
info.res_id = R.drawable.w0;
}
}
return true;
}
}
- 从服务器上请求json数据,并解析json数据
- 从服务器获取Json数据,并解析
- 关于C#向服务器请求json数据并解析
- JQuery之利用Ajax请求远程服务器上的json格式数据并解析
- 从服务器获取数据(json数据,json集合数组数据)并解析
- 获取服务器json数据并解析显示listview上
- unity3d请求json数据并解析
- [Unity3d]u3d请求json数据并解析
- extjs前台请求json数据,并解析
- http请求返回并解析json数据
- unity请求json数据并解析
- URL请求并解析JSON数据
- http请求返回并解析json数据
- unity请求json数据并解析
- 从服务器上获取xml、json数据
- json解析服务器数据
- Flex获取服务器JSON数据并解析JSON
- 初探Android中的请求服务器并解析返回的json数据
- struts2 防止表单重复提交
- 进程与线程的一个简单解释
- jquerymobile 基础教程
- 深入浅出交换类排序算法(冒泡排序,快速排序)
- 获取相册图片及路径
- 从服务器上请求json数据,并解析json数据
- 深入浅出选择类排序算法(简单选择排序,堆排序)
- The Picture of Dorian Gray——4
- hdu 3342——Legal or Not
- Linux下库函数动态链接过程分析(转)
- 把数值转化为“00:00:00”格式
- 夺冠概率--蓝桥杯
- 机器翻译系统moses报错记录
- 表单类 文本框失去焦点jquery