IT 세상/자바세상
Java에서 JSON 사용하기 - 설정 및 간단 예제
이현민 (지후지율아빠)
2009. 3. 4. 14:31
출처: http://k-flow.tistory.com/trackback/8
Java에서 Json-lib를 사용하기 위해서 필요한 라이브러리_
eclipse 사용시 Build Path -> Add Exeternal Archives 에 추가
json-lib-2.1-jdk15.jar
jakarta commons-lang 2.3
jakarta commons-beanutils 1.7.0
jakarta commons-collections 3.2
jakarta commons-logging 1.1
ezmorph 1.0.4
Java에서 Json-lib를 사용하기 위해서 필요한 라이브러리_
eclipse 사용시 Build Path -> Add Exeternal Archives 에 추가
Source Code
json형식 ==> {"jsontest":[{"name":"Mr.Cho","location":"Seoul"}]}
import java.util.Iterator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class JSONParse {
public static void main(String[] ar) {
String s = "{\"jsontest\":[{\"name\":\"Mr.Cho\",\"location\":\"Seoul\"}]}";
JSONObject jo = JSONObject.fromObject(s);
public static void main(String[] ar) {
String s = "{\"jsontest\":[{\"name\":\"Mr.Cho\",\"location\":\"Seoul\"}]}";
JSONObject jo = JSONObject.fromObject(s);
JSONArray ja = jo.getJSONArray("jsontest");
for (Iterator i = ja.iterator(); i.hasNext();) {
JSONObject ob = (JSONObject) i.next();
JSONObject ob = (JSONObject) i.next();
String a = ob.getString("name");
String b = ob.getString("location");
String b = ob.getString("location");
System.out.println(a);
System.out.println(b);
}
}
}
System.out.println(b);
}
}
}
[출처] [펌] Java에서 Json-lib 사용하기|작성자 밤바