tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 JSON > JSON JAVA > Simple Stringer

Simple Stringer 

JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. Douglas Crockford has provided a reference implementation of JSON in Java at useful for JSON serialization and deserialization. Click here to download the compiled library. The following example shows serializing a JSON Object using JSONStringer.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.json_java.tests;

import org.json.JSONException;
import org.json.JSONStringer;

public class SimpleStringer {

   @param args
   @throws JSONException 
  public static void main(String[] argsthrows JSONException {
    JSONStringer stringer = new JSONStringer();
    String jsonStr = stringer
            .object()      //Start JSON Object
              .key("age")    //Add key-value pairs  
              .value("2 years")
            .endObject()    //End JSON Object



It gives the following output,
{ "name":"Sriram", "age":"2 years", "hobby":"painting" }


bl  br