网络请求数据

public class NetWorkUtils {
    
    public static String getStr(String path){
        
        HttpClient http=new DefaultHttpClient();
        HttpGet get=new HttpGet(path);
        try {
            HttpResponse response = http.execute(get);
            if(response.getStatusLine().getStatusCode()==200){
                return EntityUtils.toString(response.getEntity(),"gbk");
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

}

============================================

private void httpData() {
        new AsyncTask<String, Void, String>(){

            
            @Override
            protected String doInBackground(String... params) {
                String json=NetWorkUtils.getStr(params[0]);
                return json;
            }
            protected void onPostExecute(String result) {
                Gson gson=new Gson();
                List<Bean>    bean=gson.fromJson(result,
                        new TypeToken<List<Bean>>(){}.getType());
                for (Bean bean2 : bean) {
                    String type=bean2.type;
                    if("vpimg".equals(type)){
                        vplist=bean2.item;
                    }else if("listmr".equals(type)){
                        list1=bean2.item;
                    }else if("listxl".equals(type)){
                        list2=bean2.item;
                    }
                    else if("listxy".equals(type)){
                        list3=bean2.item;
                    }
                    else if("listjg".equals(type)){
                        list4=bean2.item;
                    }
                    
                    
                }
            };
        }.execute(path);
        
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值