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

Type Values 

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 getting typed values from a JSON object.

File Name  :  
com/bethecoder/tutorials/json_java/tests/TypeValues.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.json_java.tests;

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

public class TypeValues {
  
  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {
    JSONObject jsonObj = new JSONObject(
        "{" +
          "name : Sriram," +
           "age : 2, " +
           "salry: 999999.99" +
        "}"
    );
    
    System.out.println(jsonObj.getString("name"));  //returns string
    System.out.println(jsonObj.getInt("age"));  //returns int
    System.out.println(jsonObj.getDouble("salry"));  //returns double
  }

}
   

It gives the following output,
Sriram
2
999999.99


                    Print

   



Books Recommendation

 
 
bl  br