create json object

Viewed 715

I want to store some offline data from a webpage.I am trying to use Json.i want to use this webpage in tablets and smart phone. Can any one help me in adding the jar

import java.io.FileWriter;
import java.io.IOException;
import com.sun.
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class Jsonnn {
     public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "asdf");
    obj.put("age", new Integer(100));

    JSONArray list = new JSONArray();
    list.add("msg 1");
    list.add("msg 2");
    list.add("msg 3");

    obj.put("messages", list);

    try {

        FileWriter file = new FileWriter("c:\\test.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

     }

}
1 Answers
Related