org.json-속성

속성 클래스는 속성 텍스트를 JSONObject로 또는 그 반대로 변환하는 정적 메서드를 제공합니다.

다음 방법은 예제에서 다룹니다.

  • toJSONObject(Properties) − 속성 데이터를 JSONObject Object로 변환합니다.

  • 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}