More Tutorials| Bioinformatics| Open Source| Photoshop| Questions? | Software Development
 

"JSONArray" example in Java

In this part of JSON tutorial you will study how to use JSONArray in Java. JSONArray is a sequential and ordered way of collection values.

"JSONArray" example in Java

                         

In this part of JSON tutorial you will study how to use JSONArray in Java. JSONArray is a sequential and ordered way of collection values.It may consists of Boolean, JSONArray, JSONObject, Number and String or the JSONObject.NULL objects.

To have functionality of JSON in your java program you must have JSON-lib. JSON-lib also requires following "JAR" files:

  1. commons-lang.jar 
  2. commons-beanutils.jar
  3. commons-collections.jar
  4. commons-logging.jar
  5. ezmorph.jar
  6. json-lib-2.2.2-jdk15.jar

JSON-lib is a java library for that transforms beans, collections, maps, java arrays and XML to JSON and then for retransforming them back to beans, collections, maps and others.

In this example we are going to use JSONArray for creating an object of JSONArray and then we will print this array object . For using JSONArray class we have to import package "net.sf.json". To add elements in this object we have used add() method. Here is the full example code of JSONJavaArray.java  as follows:

FirstJSONJava.java

import net.sf.json.JSONArray;

public class JSONJavaArray
{
  public static void main(String args[]){
   JSONArray arrayObj=new JSONArray();
   arrayObj.add("name :");
   arrayObj.add("Amit Kumar");
   arrayObj.add("Max.Marks :");
   arrayObj.add(new Integer(100));
   arrayObj.add("Min.Marks");
   arrayObj.add(new Double(40));
   arrayObj.add("Scored");
   arrayObj.add(new Double(66.67));
   System.out.println(arrayObj);
  }
}  

To run this example you have to follow these few steps as follows:

Output:


Download Source Code

 

                         

» View all related tutorials
Related Tags: java javascript c arrays json array tutorials script object io objects parse sed ip vi tutorial ria this message create

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.