반응형

JSON 형식의 데이터를 받아서 jqGrid에 뿌려주는 경우 참고하세요~


JSONParser parser = new JSONParser();

JSONObject jsonObject = null;

StringBuilder sbParam = new StringBuilder();


if(config.getProperty("mode").equalsIgnoreCase("local")){  //json 파일을 직접 불러서 jqGrid에 뿌려주는 경우

String jsonPath = '패스는 상황에 맞게 변경 할 것~';

Object obj = parser.parse(new FileReader(jsonPath));

jsonObject = (JSONObject)obj;

}else {    // 서버 URL 호출로 JSON 형식으로 받아서 jqGrid에 JSONObject 형식으로 리턴하는 경우

String url = sbParam.toString();

URL getURL = new URL(url);

HttpURLConnection con = (HttpURLConnection)getURL.openConnection();

jsonObject = (JSONObject)parser.parse(new InputStreamReader(con.getInputStream()));

con.disconnect();

}

return jsonObject.toString();

반응형

+ Recent posts