HttpEntity的结果解析为JSON
String result=EntityUtils.toString(response.getEntity());
JSONObject obj = JSONObject.parseObject(result);
System.out.println(obj.toString());
String source = obj.getString("_source");
System.out.println(source);
Map mapType = JSON.parseObject(result,Map.class);
for (Object object : mapType.keySet()){
System.out.println("key为:"+object+"值为:"+mapType.get(object));
}
也可以解析为JSONArray
JSONArray objs = JSONArray.parseArray(result);
JSONArray 遍历方式
public static void f2(JSONArray ja) {
for(int i=0;i<ja.size();i++) {
System.out.println(ja.getJSONObject(i).get("id"));
}
}