● json simple을 사용하여 작성 ( json simple 링크 )
● sample
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class JsonArrayParseTest {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
StringBuffer buf = new StringBuffer();
buf.append(" { \"category\" [ { \"cateName\" : \"mycate1\", \"order\" : 001 } \n");
buf.append(" , { \"cateName\" : \"mycate2\", \"order\" : 002 } \n");
buf.append(" , { \"cateName\" : \"mycate3\", \"order\" : 003 } ]} \n");
System.out.println(buf.toString());
JSONParser json = new JSONParser();
JSONObject jobj = (JSONObject)json.parse(buf.toString());
JSONArray jarray = (JSONArray)jobj.get("category");
System.out.println("sessionid : " + jarray.size());
for(int i=0; i<jarray.size(); i++) {
JSONObject tempObj = (JSONObject)jarray.get(i);
System.out.print("cateName : " + tempObj.get("cateName"));
System.out.print(" - ");
System.out.println("order : " + tempObj.get("order"));
}
}
}
|