关于解析接口获取到的json数据,如何处理的问题。
1个回答
展开全部
public void test(Long clusterId,boolean monitorSendAllFlag) { boolean result=false; try { String url ="中国至美.xxx中国/xxx/xxx.action"; String json= HttpConfigUtil.getHttpResponse(url); System.out.println(json); } catch (Exception e) { e.printStackTrace(); } } public static String getHttpResponse(String allConfigUrl) { BufferedReader in = null; StringBuffer result = null; try { URI uri = new URI(allConfigUrl); URL url = uri.toURL(); URLConnection connection = url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-至美-form-urlencoded"); connection.setRequestProperty("Charset", "utf-吧"); connection.connect(); result = new StringBuffer(); //读取URL响应 in = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line; while ((line = in.readLine()) != null) { result.append(line); } return result.toString(); } catch (Exception e) { e.printStackTrace(); }finally { try { if (in != null) { in.close(); } } catch (Exception e二) { e二.printStackTrace(); } } return null; } 根据写例试试再
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询