12/22/09

json simple example

package jsonexample;
import net.sf.json.*;




/**
*
 * @author raghuram
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
JSONObject object=new JSONObject();
object.put("id","er345");
object.put("designation","dfsf");
object.put("ctc",new Double(40));
object.put("allowance",new Double(66.67));
object.put("nickname","Babu");
System.out.println(object);

JSONArray jar=new JSONArray();
jar.add("hi");
jar.add(new Integer(25));

System.out.println("=======decode=======");


System.out.println("======the 2nd element of array======");
System.out.println(jar.get(1));
System.out.println();

JSONObject obj2=(JSONObject)jar.get(1);
System.out.println("======field \"1\"==========");
System.out.println(obj2.get("1"));












}

}

No comments:

Post a Comment

Popular Posts