1. 程式人生 > >HttpEntity的結果解析為JSON

HttpEntity的結果解析為JSON

println pre 生成 pty ons .get 解析 set ring

String result=EntityUtils.toString(response.getEntity()); // 方式1 // 生成 JSON 對象 JSONObject obj = JSONObject.parseObject(result); System.out.println(obj.toString()); String source = obj.getString("_source"); System.out.println(source); // 方式2 // 解析成Map對象 Map mapType = JSON.parseObject(result,Map.class); for (Object object : mapType.keySet()){ System.out.println("key為:"+object+"值為:"+mapType.get(object)); }

HttpEntity的結果解析為JSON