-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJason_Utility.java
More file actions
38 lines (29 loc) · 1.24 KB
/
Copy pathJason_Utility.java
File metadata and controls
38 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sample;
import java.io.FileReader;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class Jason_Utility {
public static void main(String[] args) {
JSONParser parser = new JSONParser();
// try {
//FileReader reader = new FileReader("F:\\Workspace2024\\ado\\Mydata.json") ;
try {
Object obj = parser.parse( new FileReader("F:\\Workspace2024\\ado\\Mydata.json"));
JSONObject jsonObject = (JSONObject)obj;
String name = (String)jsonObject.get("Name");
String course = (String)jsonObject.get("Course");
JSONArray subjects = (JSONArray)jsonObject.get("Subjects");
System.out.println("Name: " + name);
System.out.println("Course: " + course);
System.out.println("Subjects:");
Iterator iterator = subjects.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
} catch(Exception e) {
e.printStackTrace();
}
}
}