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;

}

}

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-12-16
  • 2022-01-18
猜你喜欢
  • 2021-07-05
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案