Android中通过HttpPost、HttpResponse两个类,访问某一接口。

再使用JSONObject类,来从返回的json数据中解析出数据给Bean实体类。

不啰嗦,见方法块代码:

public static AboutModel getAboutMsg(Context ctx) {String requestUrl = WXConstants.getAboutMsgURL;try {HttpPost request = new HttpPost(requestUrl);HttpResponse httpResponse = new DefaultHttpClient().execute(request);if (httpResponse.getStatusLine().getStatusCode() == 200) {String retSrc = EntityUtils.toString(httpResponse.getEntity());JSONObject json = new JSONObject(retSrc);String qqMsg = json.getString("qqmsg");String url = json.getString("url");AboutModel model = new AboutModel();model.qqMsg = qqMsg;model.companyUrl = url;return model;}} catch (Exception e) {// TODO Auto-generated catch blockExceptionThrowUtil.ThrowException(ctx, e);e.printStackTrace();}return null;}
注意:网络访问要try-catch{}


注:解析的json如下

{"qqmsg":"客服QQ:111222333","url":"http://www.baidu.com"}








更多相关文章

  1. “罗永浩抖音首秀”销售数据的可视化大屏是怎么做出来的呢?
  2. Nginx系列教程(三)| 一文带你读懂Nginx的负载均衡
  3. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  4. Android实现文件选择
  5. Android中打电话的数据流程分析
  6. android的正向传值与反向传值
  7. Android(安卓)与 SQLite
  8. android简单的多人聊天程序--借助Bmob后台数据库
  9. Android(安卓)使用Intent和Bundle传递数据及如何传递enum

随机推荐

  1. Android Studio 出现 Error: NDK integra
  2. Android APP 设置启动的第一张图片
  3. ubuntu 编译 ffmpeg For Android
  4. android一键清除最近应用按钮
  5. Android外接扫码枪监听普通输入事件
  6. android音乐播放器(2)
  7. 判断Android客户端网络是否连接
  8. Android(安卓)之 在内存中读/取数据
  9. Android Studio关闭双击Shift打开全局搜
  10. Android studio引入百度地图时的bug