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 - JSONML
org.json - JSONML
JSONML class provides static methods to convert a XML text into a JSONArray, and vice versa.
Following methods are covered in the example.
toJSONArray(String) − Converts a XML to JSONArray Object.
toJSONObject(String) − Converts a XML to JSONObject Object.
toString(JSONArray) − Gives a XML from a JSONArray Object.
toString(JSONObject) − Gives a XML from a JSONObject Object.
Example
import org.json.JSONArray; import org.json.JSONML; import org.json.JSONObject; pubpc class JSONDemo { pubpc static void main(String[] args) { JSONArray pst = new JSONArray(); pst.put("name"); pst.put("Robert"); System.out.println("XML from a JSONArray: "); String xml = JSONML.toString(pst); System.out.println(xml); System.out.println("JSONArray from a XML: "); pst = JSONML.toJSONArray(xml); System.out.println(pst); System.out.println("JSONObject from a XML: "); JSONObject object = JSONML.toJSONObject(xml); System.out.println(object); System.out.println("XML from a JSONObject: "); xml = JSONML.toString(object); System.out.println(xml); } }
Output
XML from a JSONArray: <name>Robert</name> JSONArray from a XML: ["name","Robert"] JSONObject from a XML: {"childNodes":["Robert"],"tagName":"name"} XML from a JSONObject: <name>Robert</name>Advertisements