CloseableHttpResponse

时间:2025-02-18 08:59:55
  • import ;  
  • import ;  
  • import ;  
  • import ;  
  • import ;  
  • import ;  
  • import ;  
  • import ;  
  •   
  • import ;  
  • import ;  
  • import ;  
  •   
  • /** 
  •  * Created by 清水66 on 2017/8/28. 
  •  */  
  • public class JsonGet {  
  •     public static void main(String[] args){  
  •         //创建HttpClientBuilder  
  •         HttpClientBuilder httpClientBuilder = ();  
  •         //HttpClient  
  •         CloseableHttpClient closeableHttpClient = ();  
  •         HttpGet httpGet = new HttpGet("/myapp/app/?apkName=&apkCode=157&p=1&fresh=0.02709822286851704&contextData=");  
  •         (());  
  •         try {  
  •             //执行get请求  
  •             HttpResponse httpResponse = (httpGet);  
  •             //获取响应消息实体  
  •             HttpEntity entity = ();  
  •             //响应状态  
  •             ("status:" + ());  
  •             //判断响应实体是否为空  
  •             if (entity != null) {  
  •                 ("contentEncoding:" + ());  
  •                 parseJsonGet((entity));  
  •             }  
  •         } catch (IOException e) {  
  •             ();  
  •         } finally {  
  •             try {                //关闭流并释放资源  
  •                 ();  
  •             } catch (IOException e) {  
  •                 ();  
  •             }  
  •         }  
  •     }  
  •     //解析Json数据  
  •     public static void parseJsonGet(String jsonString){  
  •         JSONObject jsonObject = (jsonString);  
  •         //AppCommentsData类,存放评论的作者、评论内容等  
  •         List<AppCommentsData> list = new ArrayList<AppCommentsData>();  
  •         JSONObject obj= ("obj");  
  •         //商品评论信息  
  •         JSONArray jsonArray = ("commentDetails");  
  •         for(int i =0;i<();i++){  
  •             AppCommentsData appCommentsData = new AppCommentsData();  
  •             appCommentsData.setApp_id(1);  
  •             appCommentsData.setStore_id(1011);  
  •             //评论作者  
  •             ((i).getString("nickName"));  
  •             //商品评论内容  
  •             ((i).getString("content"));  
  •             //评分  
  •             ((i).getInt("score"));  
  •             (appCommentsData);  
  •         }  
  •         ("输出appCommentsData//");  
  •         for (int i=0;i<();i++){  
  •             AppCommentsData appCommentsData = (i);  
  •             ("name: ="+());  
  •             ("content: ="+());  
  •             ("score: ="+());  
  •         }  
  •     }  
  • }