HttpEntity的结果解析为JSON

        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));  
        }  

猜你喜欢

转载自blog.51cto.com/59465168/2330838
今日推荐