array 형식( [ ... ] ) 으로 된 json 을 다루는 방법이다.




import org.json.JSONArray; import org.json.JSONObject; public void map(Integer key, BasicDBObject value, Context context) throws IOException, InterruptedException { String str = null; try { str = value.getString(“i”); JSONArray jsonObj = new JSONArray(str); for (int i = 0; i < jsonObj.length(); i++) { JSONObject obj = jsonObj.getJSONObject(i); int ikey = obj.getInt(“i”); int ivalue = obj.getInt(“v”); ....



위의 예제 코드처럼 JSONArray 를 사용하면 된다.


JSONArray 에서 getSJONObject( [index] ) 를 사용하여 JSONObject 를 뽑아내서 사용하면 된다.




https://mvnrepository.com/artifact/org.json/json


관련 라이브러리는 위에서 받을 수 있다.


원하는 버전을 누른 다음 bundle 이라고 되어 있는 것을 누르면 jar 파일을 받을 수 있다.


혹, 바로 받아보고 싶은 분들을 위해 


wget http://central.maven.org/maven2/org/json/json/20180813/json-20180813.jar 


리눅스에서 위의 명령어로 바로 180813 버전 java json jar 파일을 받을 수 있다.


+ Recent posts