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

Increment 

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 http://json.org/ useful for JSON serialization and deserialization. Click here to download the compiled library. The following example shows incrementing the number properties of a JSONObject using increment method.

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

import org.json.JSONException;
import org.json.JSONObject;

public class Increment {

  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {

    JSONObject obj = new JSONObject();
    obj.put("year"2010);
    System.out.println(obj.toString(2));
    
    obj.increment("year").increment("age");
    System.out.println(obj.toString(2));
    
    obj.increment("year").increment("age");
    System.out.println(obj.toString(2));
    
    obj.increment("year").increment("age");
    System.out.println(obj.toString(2));
  }

}
   

It gives the following output,
{"year": 2010}

{
  "age": 1,
  "year": 2011
}

{
  "age": 2,
  "year": 2012
}

{
  "age": 3,
  "year": 2013
}



 
  


  
bl  br