首页 > Web开发 > 详细

获取HttpResponse并解析JSON数据

时间:2015-10-27 15:03:49      阅读:1410      评论:0      收藏:0      [点我收藏+]

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;

}

}

获取HttpResponse并解析JSON数据

原文:http://www.cnblogs.com/webster1/p/4913894.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!