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 - JSONObject
org.json - JSONObject
JSONObject class is a unordered collection of key-value pairs. It provides methods to access values by key and to put values. Following types are supported −
Boolean
JSONArray
JSONObject
Number
String
JSONObject.NULL object
Example
import org.json.JSONArray; import org.json.JSONObject; pubpc class JSONDemo { pubpc 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 pst = new JSONArray(); pst.put("foo"); pst.put(new Integer(100)); jsonObject.put("pst",pst); System.out.println(jsonObject); } }
Output
{"Active":true,"Other Details":null,"ID":1,"Fees":1000.21,"pst":["foo",100],"Name":"Robert"}Advertisements