-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSONObject.java
More file actions
64 lines (54 loc) · 1.03 KB
/
JSONObject.java
File metadata and controls
64 lines (54 loc) · 1.03 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
public class JSONObject
{
private JSONVariable[] theVariables;
private int currSize;
public JSONObject()
{
this.theVariables = new JSONVariable[50];
this.currSize = 0;
}
public JSONVariable getVariableForName(String name)
{
for(int i = 0; i < this.currSize; i++)
{
if(this.theVariables[i].getName().equals(name))
{
return this.theVariables[i];
}
}
return null;
}
public int getCurrSize() {
return currSize;
}
public void addVariable(JSONVariable jv)
{
if(this.currSize < this.theVariables.length)
{
this.theVariables[this.currSize] = jv;
this.currSize++;
}
}
public void display()
{
System.out.println("JSON Object - Num Vars: " + this.currSize);
for(int i = 0; i < this.currSize; i++)
{
this.theVariables[i].display();
}
}
public String exportToJSON()
{
String answer = "{";
for(int i = 0; i < this.currSize; i++)
{
answer += this.theVariables[i].exportToJSON();
if(i != this.currSize-1)
{
answer += ",";
}
}
answer += "}";
return answer;
}
}