privateStringb;newThread(newRunnable(){publicvoidrun(){Stringa=connServerForResult("http://m.weather.com.cn/data/101090101.html");finalStringv="石家庄?"+parseJson(a);System.out.println("zheliv"+v);tq.post(newRunnable(){publicvoidrun(){tq.setText(v.replace("?","\n"));System.out.println("zheliv"+v);}});}}).start();}privateStringconnServerForResult(StringstrUrl){//获取HttpGet对象HttpGethttpRequest=newHttpGet(strUrl);StringstrResult="";try{//HttpClient对象HttpClienthttpClient=newDefaultHttpClient();//获得HttpResponse对象HttpResponsehttpResponse=httpClient.execute(httpRequest);if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){//取得返回的数据strResult=EntityUtils.toString(httpResponse.getEntity());System.out.println("zheli");}}catch(ClientProtocolExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}Log.i("Infor",strResult);returnstrResult;//返回结果}//对于返回的结果我们通过Json解析工具进行解析。下面是解析函数的代码,其参数就是要解析的Json格式数据字符串。privateStringparseJson(StringstrResult){try{JSONObjectjsonObj=newJSONObject(strResult).getJSONObject("weatherinfo");b=jsonObj.getString("temp1");//当前日期//dayofweek=jsonObj.getString("week");//当前星期//city.setText(jsonObj.getString("city"));//城市名称//ftime=jsonObj.getInt("fchh");//更新时间(整点)【更新时间确定temp1属于哪天】//由于数据较多此处省略了部分代码,其他数据解析方法相同,大家可以照葫芦画瓢。System.out.println("zhelinn");}catch(JSONExceptione){Log.i("Erorr","Jsonparseerror");e.printStackTrace();}System.out.println("zheliv"+b);returnb;}}//时间紧张,就读取了一个字符串,其他雷同