zoukankan      html  css  js  c++  java
  • 获取HttpResponse并解析JSON数据

    package com.inesaie.trace.accommon.util;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    import org.apache.http.HttpResponse;
    import org.codehaus.jettison.json.JSONException;
    import org.codehaus.jettison.json.JSONObject;

    public class HttpEntity {

    public static JSONObject GetHttpEntity(HttpResponse response) {

    String line=null;
    JSONObject resultJsonObject=null;
    StringBuilder entityStringBuilder=new StringBuilder();
    try {
    BufferedReader b = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"),8*1024);
    while ((line=b.readLine())!=null) {
    entityStringBuilder.append(line+"/n");
    }
    //利用从HttpEntity中得到的String生成JsonObject

    resultJsonObject = new JSONObject(entityStringBuilder.toString());
    } catch (JSONException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    } catch (IOException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    // System.out.println("***httpResponse.getEntity():"+resultJsonObject);

    return resultJsonObject;

    }

    }

    群交流(262200309)
  • 相关阅读:
    沙雕玩意儿
    1558:聚会 ybt
    沙雕关于线段树的一点总结(滑稽)
    卑微
    沙雕题目 来自luogu
    甜茶好帅啊
    python 中字符串的格式化
    python的几个小程序
    python 第一课
    基于笔画宽度变换的自然场景文本检测方法
  • 原文地址:https://www.cnblogs.com/webster1/p/4913894.html
Copyright © 2011-2022 走看看