org.json-JSONObject
JSONObject 클래스는 키-값 쌍의 정렬되지 않은 컬렉션입니다. 키로 값에 액세스하고 값을 입력하는 방법을 제공합니다. 다음 유형이 지원됩니다-
Boolean
JSONArray
JSONObject
Number
String
JSONObject.NULL 객체
예
import org.json.JSONArray;
import org.json.JSONObject;
public class JSONDemo {
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Robert");
jsonObject.put("ID", 1);
jsonObject.put("Fees", new Double(1000.21));
jsonObject.put("Active", new Boolean(true));
jsonObject.put("Other Details", JSONObject.NULL);
JSONArray list = new JSONArray();
list.put("foo");
list.put(new Integer(100));
jsonObject.put("list",list);
System.out.println(jsonObject);
}
}
산출
{"Active":true,"Other Details":null,"ID":1,"Fees":1000.21,"list":["foo",100],"Name":"Robert"}