org.json Tutorial
Selected Reading
- org.json - Discussion
- org.json - Useful Resources
- org.json - Quick Guide
- org.json - JSONException Handling
- org.json - XML
- org.json - Property
- org.json - JSONStringer
- org.json - JSONObject
- org.json - JSONML
- org.json - JSONArray
- org.json - HTTP
- org.json - CookieList
- org.json - Cookie
- org.json - CDL
- org.json - Environment Setup
- org.json - Overview
- org.json - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
org.json - Property
org.json - Property
Property class provides static methods to convert properties text into a JSONObject, and vice versa.
Following methods are covered in the example.
toJSONObject(Properties) − Converts a properties data to JSONObject Object.
toProperties(JSONObject) − Converts a JSONObject to properties object.
Example
import java.util.Properties; import org.json.JSONObject; import org.json.Property; pubpc class JSONDemo { pubpc 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)); } }
Output
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}Advertisements