-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSONArrayVariable.java
More file actions
53 lines (47 loc) · 911 Bytes
/
JSONArrayVariable.java
File metadata and controls
53 lines (47 loc) · 911 Bytes
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
public class JSONArrayVariable extends JSONVariable
{
private JSONObject[] value;
private int currSize;
public JSONArrayVariable(String name)
{
super(name);
this.value = new JSONObject[50];
this.currSize = 0;
}
public JSONObject[] getValue()
{
return value;
}
public int getCurrSize() {
return currSize;
}
public void addJSONObject(JSONObject obj)
{
this.value[this.currSize] = obj;
this.currSize++;
}
@Override
void display()
{
System.out.println("JSON Array - " + this.name + " -> Num Objects: " + this.currSize);
for(int i = 0; i < this.currSize; i++)
{
this.value[i].display();
}
}
@Override
String exportToJSON()
{
String answer = "\"" + this.name + "\": [";
for(int i = 0; i < this.currSize; i++)
{
answer += this.value[i].exportToJSON();
if(i != this.currSize-1)
{
answer += ",";
}
}
answer += " ]";
return answer;
}
}