获取响应中的JASON对象

 protected BaseRes parseJsonResponse(HttpResponse httpRes, Class clz) throws Exception {

 
// 处理JSON返回结果
String jsonStr = EntityUtils.toString(httpRes.getEntity());
StringBuilder sb = new StringBuilder();
String[] jsonItems = jsonStr.split(","); 
sb.append(" parseJsonResponse - start - " + "\n");
for (String string : jsonItems) {
sb.append("  " + string + "\n");
}
sb.append(" parseJsonResponse - end - " + "\n");
LogUtils.logi(LOG_TAG, "json str:" + sb.toString());
 
JSONObject jsonObject = new JSONObject(jsonStr);
 
// 取json中response节点中的字串
String responseStr = jsonObject.getString("response");
 
// 转换器
GsonBuilder builder = new GsonBuilder();
 
// 不转换没有 @Expose 注解的字段
builder.excludeFieldsWithoutExposeAnnotation();
Gson gson = builder.create();
 
// 从JSON串转成JAVA对象
BaseRes response = gson.fromJson(responseStr, clz);
 
//added by edwar 2012-08-31 释放内存--start
jsonObject = null;
builder = null;
//added by edwar 2012-08-31 释放内存 --end
return response;
}

你可能感兴趣的:(获取响应中的JASON对象)