- org.json 教程
- org.json - 主頁
- org.json - 概覽
- org.json - 環境設定
- CSV 示例
- org.json - CDL
- Cookie 示例
- org.json - Cookie
- org.json - CookieList
- HTTP 標頭示例
- org.json - HTTP
- JSON 示例
- org.json - JSONArray
- org.json - JSONML
- org.json - JSONObject
- org.json - JSONStringer
- 屬性示例
- org.json - Property
- XML 示例
- org.json - XML
- 異常處理
- org.json - JSONException 處理
- org.json 實用資源
- org.json - 快速指南
- org.json - 實用資源
- org.json - 討論
org.json - JSONObject
JSONObject 類是無序的鍵值對集合。它提供按鍵訪問值和放置值的方法。支援以下型別 -
布林
JSONArray
JSONObject
數字
字串
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"}
廣告