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 - JSONStringer
org.json - JSONStringer
JSONStringer is a utipty class to build a JSON Text quickly which confirms to JSON Syntax rules. Each instance of JSONStringer can produce one JSON text.
Example
import org.json.JSONStringer; pubpc class JSONDemo { pubpc static void main(String[] args) { String jsonText = new JSONStringer() .object() .key("Name") .value("Robert") .endObject() .toString(); System.out.println(jsonText); jsonText = new JSONStringer() .array() .value("Robert") .value("Jupa") .value("Dan") .endArray() .toString(); System.out.println(jsonText); jsonText = new JSONStringer() .array() .value("Robert") .value("Jupa") .value("Dan") .object() .key("Name") .value("Robert") .endObject() .endArray() .toString(); System.out.println(jsonText); } }
Output
{"Name":"Robert"} ["Robert","Jupa","Dan"] ["Robert","Jupa","Dan",{"Name":"Robert"}]Advertisements