org.json – Useful Resources ”; Previous Next The following resources contain additional information on org.json library. Please use them to get more in-depth knowledge on this topic. Useful Links on org.json org.json Project Home − org.json Portal Page on Github Json Wiki − Wikipedia reference for Json Useful Books on org.json To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Category: org Json
org.json – CDL
org.json – CDL ”; Previous Next CDL class provides static methods to convert a comma delimited text into a JSONArray, and vice versa. Following methods are covered in the example. rowToJSONArray(String) − Converts a comma delimited text to JSONArray Object. rowToString(JSONArray) − Converts a JSONArray to comma delimited text. toJSONArray(String) − Converts a multi-line comma delimited text to Object of JSONArray objects. toJSONArray(JSONArray, String) − Converts a JSONArray Object and comma delimited text to JSONArray Object. Example import org.json.CDL; import org.json.JSONArray; import org.json.JSONTokener; public class JSONDemo { public static void main(String[] args) { String csvData = “INDIA, UK, USA”; //Case 1: CSV to JSON Array JSONArray jsonArray = CDL.rowToJSONArray(new JSONTokener(csvData)); System.out.println(jsonArray); //Case 2: JSONArray to CSV System.out.println(CDL.rowToString(jsonArray)); //Case 3: CSV to JSONArray of Objects csvData = “empId, name, age n” + “1, Mark, 22 n” + “2, Robert, 35 n” + “3, Julia, 18”; System.out.println(CDL.toJSONArray(csvData)); //Case 4: CSV without header jsonArray = new JSONArray(); jsonArray.put(“empId”); jsonArray.put(“name”); jsonArray.put(“age”); csvData = “1, Mark, 22 n” + “2, Robert, 35 n” + “3, Julia, 18”; System.out.println(CDL.toJSONArray(jsonArray,csvData)); } } Output [“INDIA”,”UK”,”USA”] INDIA,UK,USA [{“name”:”Mark”,”empId”:”1″,”age”:”22″}, {“name”:”Robert”,”empId”:”2″,”age”:”35″}, {“name”:”Julia”,”empId”:”3″,”age”:”18″}] [{“name”:”Mark”,”empId”:”1″,”age”:”22″}, {“name”:”Robert”,”empId”:”2″,”age”:”35″}, {“name”:”Julia”,”empId”:”3″,”age”:”18″}] Print Page Previous Next Advertisements ”;
org.json – Overview
Org.Json – Overview ”; Previous Next org.json or JSON-Java is a simple Java based toolkit for JSON. You can use org.json to encode or decode JSON data. Features Specification Compliant − JSON.simple is fully compliant with JSON Specification – RFC4627. Lightweight − It have very few classes and provides the necessary functionalities like encode/decode and escaping json. XML Conversion − It provides conversion capability from JSON to XML and vice-versa. HTTP Headers − Supports HTTP Header conversion to JSON and vice versa. Cookie − Provides support for Cookie conversion to JSON and vice versa. CDL − Provides support to convert comma separated list to JSON and vice versa. No dependency − No external library dependency. Can be independently included. Java 1.6-1.11 compatible − Source code and the binary are Java 1.6-1.11 compatible Print Page Previous Next Advertisements ”;
org.json – XML
org.json – XML ”; Previous Next XML class provides static methods to convert a XML text into a JSONObject, and vice versa. Following methods are covered in the example. toJSONObject(String) − Converts a XML to JSONArray Object. toString(JSONObject) − Gives a XML from a JSONObject Object. Example import org.json.JSONObject; import org.json.XML; public class JSONDemo { public 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(“Details”, JSONObject.NULL); //Convert a JSONObject to XML String xmlText = XML.toString(jsonObject); System.out.println(xmlText); //Convert an XML to JSONObject System.out.println(XML.toJSONObject(xmlText)); } } Output <Active>true</Active><Details>null</Details><ID>1</ID><Fees>1000.21</Fees><Name>Robert</Name> {“Active”:true,”Details”:null,”ID”:1,”Fees”:1000.21,”Name”:”Robert”} Print Page Previous Next Advertisements ”;