- org.json 教程
- org.json - 主頁
- org.json - 概覽
- org.json - 環境設定
- CSV 示例
- org.json - CDL
- Cookie 示例
- org.json - Cookie
- org.json - CookieList
- HTTP Header 示例
- org.json - HTTP
- JSON 示例
- org.json - JSONArray
- org.json - JSONML
- org.json - JSONObject
- org.json - JSONStringer
- 屬性示例
- org.json - 屬性
- XML 示例
- org.json - XML
- 異常處理
- org.json - JSONException 處理
- org.json 有用資源
- org.json - 快速指南
- org.json - 有用資源
- org.json - 討論
org.json - 屬性
Property 類提供將屬性文字轉換為 JSONObject 以及反之的靜態方法。
本示例中介紹以下方法。
toJSONObject(Properties) − 將 properties 資料轉換為 JSONObject 物件。
toProperties(JSONObject) − 將 JSONObject 轉換為 properties 物件。
示例
import java.util.Properties;
import org.json.JSONObject;
import org.json.Property;
public class JSONDemo {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("title", "This is a title text");
properties.put("subtitle", "This is a subtitle text");
System.out.println("Properties to JSON");
JSONObject jsonObject = Property.toJSONObject(properties);
System.out.println(jsonObject);
System.out.println("JSON to properties");
System.out.println(Property.toProperties(jsonObject));
}
}
輸出
Properties to JSON
{"subtitle":"This is a subtitle text","title":"This is a title text"}
JSON to properties
{subtitle = This is a subtitle text, title = This is a title text}
廣告