- 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 - 属性
- XML 示例
- org.json - XML
- 异常处理
- org.json - JSON异常处理
- org.json 有用资源
- org.json - 快速指南
- org.json - 有用的资源
- org.json - 讨论
org.json - 属性
Property 类提供静态方法将属性文本转换为 JSONObject,反之亦然。
示例中涵盖了以下方法。
toJSONObject(Properties) - 将属性数据转换为 JSONObject 对象。
toProperties(JSONObject) - 将 JSONObject 转换为属性对象。
例子
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}