/**
      * 访问数据库并返回JSON数据字符串
      *
      * @param params 向服务器端传的参数
      * @param url
      * @return
      * @throws Exception
      */
     public static String doPost(List params, String url)
             throws Exception {
         String result = null;
         // 获取HttpClient对象
         HttpClient httpClient = new DefaultHttpClient();
         // 新建HttpPost对象
         HttpPost httpPost = new HttpPost(url);
         if (params != null) {
             // 设置字符集
             HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
             // 设置参数实体
             httpPost.setEntity(entity);
         }

         /*// 连接超时
         httpClient.getParams().setParameter(
                 CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
         // 请求超时
         httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                 3000);*/
         // 获取HttpResponse实例
         HttpResponse httpResp = httpClient.execute(httpPost);
         // 判断是够请求成功
         if (httpResp.getStatusLine().getStatusCode() == 200) {
             // 获取返回的数据
             result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
         } else {
             Log.i("HttpPost", "HttpPost方式请求失败");
         }

         return result;
     }

 

 

 

其次Json数据解析:
json数据: [{"id":"67","biaoTi":"G","logo":"http://www.nuoter.com/wtserver/

resources/upload/13508741845270.png","logoLunbo":"http://www.nuoter.com/

wtserver/resources/upload/13509015004480.jpg","yuanJia":"0","xianJia":"0"},{"id":"64","bi

aoTi":"444","logo":"http://www.nuoter.com/wtserver/resources/upload/13508741704400.png"

"logoLunbo":"http://172.16.1.75:8080/wtserver/resources/upload/13508741738500.png","yuanJia":

"0","xianJia":"0"},{"id":"62","biaoTi":"jhadasd","logo":"http://www.nuoter.com/wtserver/resources/uplo

ad/13508741500450.png","logoLunbo":"http://172.16.1.75:8080/wtserver/resources/upload/13508741557450.png",

"yuanJia":"1","xianJia":"0"}]

 

 

 

稳定

产品可用性高于99.9%

贴心

全国7*24小时客服热线

专业

产品经理在线技术支持

快速

快速建站上线运营快

承诺

我们选择声誉

坚持

10年专注高端品质开发
  • 返回顶部