-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathParsingJSON.java
More file actions
77 lines (58 loc) · 1.88 KB
/
ParsingJSON.java
File metadata and controls
77 lines (58 loc) · 1.88 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package controller;
import kong.unirest.json.JSONObject;
import java.util.Iterator;
import java.util.Set;
public class ParsingJSON {
private String symbol;
private String dateOfMonth;
private String open;
private String high;
private String low;
private String close;
private String volume;
public void makeMonthObjects(String JSON){
try {
JSONObject stock = new JSONObject(JSON);
JSONObject meta = stock.getJSONObject("Meta Data");
JSONObject monthly = stock.getJSONObject("Monthly Time Series");
symbol = meta.getString("2. Symbol");
Set<String> setMonth = monthly.keySet();
Iterator monthIterator = setMonth.iterator();
while (monthIterator.hasNext()){
Object o = monthIterator.next();
JSONObject monthlyJSONObject = monthly.getJSONObject((String) o);
dateOfMonth = (String) o;
open = monthlyJSONObject.getString("1. open");
high = monthlyJSONObject.getString("2. high");
low = monthlyJSONObject.getString("3. low");
close = monthlyJSONObject.getString("4. close");
volume = monthlyJSONObject.getString("5. volume");
monthIterator.next();
}
} catch (Exception e){
System.err.println(e.getMessage() );
System.exit(0);
}
}
public String getSymbol() {
return this.symbol;
}
public String getDateOfMonth() {
return this.dateOfMonth;
}
public String getOpen() {
return this.open;
}
public String getHigh() {
return this.high;
}
public String getLow() {
return this.low;
}
public String getClose() {
return this.close;
}
public String getVolume() {
return this.volume;
}
}