//得到home页的新闻 public void getNewsData(){ RequestParams params =new RequestParams(Ipconfig.homeNewsUrl); //params.setSslSocketFactory(...); // 设置ssl params.addQueryStringParameter("page", "0"); params.addQueryStringParameter("size", "14"); params.addQueryStringParameter("keyword", ""); if(BigDataExpoApplication.getLocalLanguege().contains("en")){ params.addQueryStringParameter("lang", "en"); }else{ params.addQueryStringParameter("lang", "zh-cn"); } params.addQueryStringParameter("channel", "2"); x.http().get(params, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { try { JSONObject jsonObject = new JSONObject(result); int code = jsonObject.optInt("code"); String message =jsonObject.optString("message"); if (code == 0) { JSONObject data=jsonObject.getJSONObject("data"); JSONArray newsList=data.getJSONArray("list"); for(int i=0;i<newsList.length();i++){ JSONObject newsListObj=newsList.getJSONObject(i); String authorname=newsListObj.getString("authorname"); String created_at=newsListObj.getString("created_at"); String editor=newsListObj.getString("editor"); String face=newsListObj.getString("face"); String id=newsListObj.getString("id"); String summary=newsListObj.getString("summary"); String title=newsListObj.getString("title"); String updated_at=newsListObj.getString("updated_at"); NewsModel newsModel=new NewsModel(); newsModel.setAuthorname(authorname); newsModel.setCreated_at(created_at); newsModel.setEditor(editor); newsModel.setFace(face); newsModel.setId(id); newsModel.setSummary(summary); newsModel.setTitle(title); newsModel.setUpdated_at(updated_at); homeNewsList.add(newsModel); } mHandler.sendEmptyMessage(GET_NEWS); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(Throwable ex, boolean isOnCallback) { Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onCancelled(CancelledException cex) { Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show(); } @Override public void onFinished() { } }); }
xutils get方式获取数据
最新推荐文章于 2018-10-15 15:48:54 发布