Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (30 loc) · 1.01 KB

File metadata and controls

47 lines (30 loc) · 1.01 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
38
39
40
41
42
43
44
45
46
47
package json;
import java.io.FileReader;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
/*
* .json파일을 JSONArray나 JSONObject로 변환
* JSON파서 - JSONParser(json-simple.jar라이브러리내에서)
*/
public class JSONParserTeset {
public static void main(String[] args) throws Exception{
//1. JSONParser를 생성
JSONParser parser = new JSONParser();
//2. json파싱하기
JSONObject root =
(JSONObject)parser.parse(
new FileReader("src/json/mydata.json"));
//3. JSONObject에서 데이터 읽기
String name = (String)root.get("name");
String age = (String)root.get("age");
System.out.println("name:"+name);
System.out.println("age:"+age);
//4. JSONArray에서 데이터읽기
JSONArray subjectlist = (JSONArray)root.get("subject");
for (int i = 0; i <subjectlist.size(); i++) {
String subject = (String)subjectlist.get(i);
System.out.println("Subject:"+subject);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.