Repository navigation
Expand file tree
/
Copy pathPnJsonObject.java
More file actions
85 lines (67 loc) · 1.8 KB
/
Copy pathPnJsonObject.java
File metadata and controls
85 lines (67 loc) · 1.8 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
78
79
80
81
82
83
84
85
package com.pubnub.api;
import java.io.StringReader;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
class PnJsonObject extends PnJsonElement {
JsonObject jso;
JsonParser jsonParser = new JsonParser();
public PnJsonObject() {
jso = new JsonObject();
}
public PnJsonObject(Object o) {
jso = (JsonObject) o;
}
public PnJsonObject(String text) throws PnJsonException {
try {
JsonReader jsr = new JsonReader(new StringReader(text));
jsr.setLenient(true);
this.jso = (JsonObject) jsonParser.parse(jsr);
} catch (Exception e) {
throw new PnJsonException(e);
}
}
public void put(String key, Object value) throws PnJsonException {
}
public Object getBaseObject() {
return jso;
}
public String getString(String key) throws PnJsonException {
// TODO Auto-generated method stub
return null;
}
public Object get(String key) throws PnJsonException {
try {
return jso.get(key);
} catch (JsonParseException e) {
throw new PnJsonException(e);
}
}
public void remove(String key) {
jso.remove(key);
}
public int length() {
return jso.entrySet().size();
}
public PnJsonObject getJSONObject(String key) throws PnJsonException {
try {
return new PnJsonObject(jso.get(key).toString());
} catch (JsonParseException e) {
throw new PnJsonException(e);
}
}
public String toString() {
String s = jso.toString();
if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
s = s.substring(1, s.length() - 1);
}
return s;
}
public static String removeExtraQuotes(String s) {
if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
s = s.substring(1, s.length() - 1);
}
return s;
}
}