Skip to content

Latest commit

 

History

History
49 lines (47 loc) · 1.28 KB

README.md

File metadata and controls

49 lines (47 loc) · 1.28 KB

Java JSON package

Install:

  • Download the latest release.
  • Add package to your build using command-line, or your IDE like Eclipse or Netbeans.

How to use:

Here is an example on how to make a new JSON object:

JSONObject obj = new JSONObject();
obj.put("$id", "User-info");
obj.put("name", "Gelobt");
obj.put("age", 16);
obj.put("isAlive", true);

& here is an example on how to make a new JSON array:

JSONArray arr = new JSONArray();
arr.add("Java");
arr.add("C++");
arr.add("Cats");

then you can put this array in the JSON object you`ve just created:

obj.put("THINGS I LOVE", arr);

last but not least, write this JSON object in a JSON file:

obj.write(new File("User-info.json"));

& here is your JSON file:

{
     "isAlive":true
     ,"name":"Gelobt"
     ,"THINGS I LOVE":     [
          "Java"
          ,"C++"
          ,"Cats"
     ]

     ,"age":16
     ,"$id":"User-info"
}

Repo Index:

License: