출처: 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 사용하기|작성자 밤바
'IT 세상 > 자바세상' 카테고리의 다른 글
file (0) | 2009.10.06 |
---|---|
FindBugs + Eclipse + Maven2 + Hudson (0) | 2009.05.11 |
[펌]이클립스에서 JAVADOC 만들기 (0) | 2009.03.03 |
Spring MVC의 특징 (0) | 2009.01.28 |
Base64 Encode & Decode By Javascript [펌] (0) | 2008.11.28 |