Skip to content

Commit e9c6a62

Browse files
committed
add comments.
1 parent 2142899 commit e9c6a62

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ To install the library add:
1515
maven { url "https://jitpack.io" }
1616
}
1717
dependencies {
18-
compile 'com.github.webee:java-json-api:v1.0.0'
18+
compile 'com.github.webee:java-json-api:v1.1.0'
1919
}
2020
```

src/main/java/com/github/webee/json/JSONArray.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface JSONArray {
88
JSONType getType(int index);
99

1010
boolean isNull(int index);
11+
// get the pure java object that correspond to it's type.
1112
Object get(int index);
1213
Boolean getBoolean(int index);
1314
Integer getInteger(int index);

src/main/java/com/github/webee/json/JSONObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface JSONObject {
1111
JSONType getType(String key);
1212

1313
boolean isNull(String key);
14+
// get the pure java object that correspond to it's type.
1415
Object get(String key);
1516
Boolean getBoolean(String key);
1617
Integer getInteger(String key);

src/main/java/com/github/webee/json/JSONType.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Created by webee on 16/11/25.
55
*/
66
public enum JSONType {
7-
Null,
8-
Boolean,
9-
Number,
10-
String,
11-
Object,
12-
Array,
7+
Null, // -> null
8+
Boolean, // -> Boolean
9+
Number, // -> Number
10+
String, // -> String
11+
Object, // -> Map<String, Object>
12+
Array, // -> Object[]
1313
}

src/main/java/com/github/webee/json/Utils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
* Created by webee on 16/11/25.
88
*/
99
public final class Utils {
10+
/**
11+
* judge value's json type.
12+
* @param value the value to judge.
13+
* @return the json type.
14+
*/
1015
public static JSONType getType(Object value) {
1116
if (value == null) {
1217
return JSONType.Null;
@@ -22,10 +27,19 @@ public static JSONType getType(Object value) {
2227
return JSONType.Object;
2328
} else if (value instanceof Object[]) {
2429
return JSONType.Array;
30+
} else if (value instanceof JSONObject) {
31+
return JSONType.Object;
32+
} else if (value instanceof JSONArray) {
33+
return JSONType.Array;
2534
}
2635
return null;
2736
}
2837

38+
/**
39+
* convert JSONArray to a Object[] array mixed tree with pure java objects.
40+
* @param array the JSONArray to convert.
41+
* @return the pure java objects array mixed tree.
42+
*/
2943
public static Object[] arrayToObjects(JSONArray array) {
3044
if (array == null) {
3145
return null;
@@ -38,6 +52,11 @@ public static Object[] arrayToObjects(JSONArray array) {
3852
return res;
3953
}
4054

55+
/**
56+
* convert JSONObject to a Map<String, Object> tree with pure java objects.
57+
* @param object the JSONObject to convert.
58+
* @return the pure java objects tree .
59+
*/
4160
public static Map<String, Object> objectToMap(JSONObject object) {
4261
if (object == null) {
4362
return null;
@@ -50,6 +69,11 @@ public static Map<String, Object> objectToMap(JSONObject object) {
5069
return res;
5170
}
5271

72+
/**
73+
* convert value to pure java objects.
74+
* @param value the value to convert.
75+
* @return pure java object.
76+
*/
5377
public static Object resolveValue(Object value) {
5478
if (value instanceof JSONArray) {
5579
return Utils.arrayToObjects((JSONArray) value);

0 commit comments

Comments
 (0)