org.json - JSONStringer


Advertisements

JSONStringer is a utility 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;

public class JSONDemo {
   public 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("Julia")      
         .value("Dan")
         .endArray()                       
         .toString();
      System.out.println(jsonText);

      jsonText = new JSONStringer()
         .array()
         .value("Robert")      
         .value("Julia")      
         .value("Dan")
         .object()
         .key("Name")
         .value("Robert")                            
         .endObject()  
         .endArray()             
         .toString();
      System.out.println(jsonText);
   }
}

Output

{"Name":"Robert"}
["Robert","Julia","Dan"]
["Robert","Julia","Dan",{"Name":"Robert"}]

Useful Video Courses


Video

Reproduction in Organisms

18 Lectures 1.5 hours

Dr. Saatya Prasad

Video

Computer Organization

107 Lectures 13.5 hours

Arnab Chakraborty

Video

Basic Principles of Organic Chemistry

75 Lectures 5 hours

Revathi Ramachandran

Video

Work Area Organization for Increased Office Productivity

14 Lectures 44 mins

Zach Miller

Video

Get Organized

12 Lectures 54 mins

Prof. Paul Cline, Ed.D

Video

Organic Chemistry: How to Build People

54 Lectures 4 hours

Gilad James, PhD

Advertisements