Skip to content

Commit f96695c

Browse files
author
ken.xu
committed
tt
1 parent 44d6e0a commit f96695c

File tree

9 files changed

+48
-25
lines changed

9 files changed

+48
-25
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build
2+
.DS_Store
3+
Thumbs.db
4+

src/ws/http/json/CaseType.java renamed to src/ws/http/doc/json/CaseType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ws.http.json;
1+
package ws.http.doc.json;
22

33
import java.lang.reflect.Method;
44
import java.util.regex.Matcher;

src/ws/http/doc/json/JSON.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ws.http.doc.json;
2+
3+
public class JSON {
4+
5+
public static String toJSON(Object obj)
6+
{
7+
return ObjectTo.toJSON(obj);
8+
}
9+
10+
public static Object parseJSON(String text) {
11+
return (null == text || text.isEmpty()) ? null : ToObject.parse(text);
12+
}
13+
14+
15+
}

src/ws/http/json/JSONArray.java renamed to src/ws/http/doc/json/JSONArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ws.http.json;
1+
package ws.http.doc.json;
22

33
import java.util.ArrayList;
44

src/ws/http/json/JSONObject.java renamed to src/ws/http/doc/json/JSONObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ws.http.json;
1+
package ws.http.doc.json;
22

33
import java.util.HashMap;
44

src/ws/http/json/ObjectTo.java renamed to src/ws/http/doc/json/ObjectTo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ws.http.json;
1+
package ws.http.doc.json;
22

33
import java.lang.reflect.Array;
44
import java.lang.reflect.Field;
@@ -55,7 +55,7 @@ static String array2Json(Object array) {
5555
StringBuffer sb = new StringBuffer();
5656
sb.append('[');
5757

58-
// 此处减1是为了下面的 逗号 追加
58+
// �˴���1��Ϊ������� ���� ׷��
5959
int len = Array.getLength(array) - 1;
6060
if (len > -1) {
6161
int i;

src/ws/http/json/ToObject.java renamed to src/ws/http/doc/json/ToObject.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package ws.http.json;
1+
package ws.http.doc.json;
22

33
import java.util.HashMap;
44
import java.util.Stack;
55

66
public class ToObject {
7-
7+
88
public static Object parse(String text) {
9-
return (null == text || text.isEmpty()) ? null : parseJSON(text);
9+
return (null == text || text.isEmpty()) ? null : ToObject.parseJSON(text);
1010
}
1111

1212
public static <T extends Object> T parse(String text, Class<T> clazz) {
@@ -15,11 +15,12 @@ public static <T extends Object> T parse(String text, Class<T> clazz) {
1515
return CaseType.objectValue(parseJSONObject(text), clazz);
1616
}
1717

18-
public static JSONArray parseJSONArray(String text) {
18+
@SuppressWarnings("unused")
19+
private static JSONArray parseJSONArray(String text) {
1920
return ((null == text || text.isEmpty()) || !isJSONArray(text)) ? null : JSONArray.class.cast(parseJSON(text));
2021
}
2122

22-
public static JSONObject parseJSONObject(String text) {
23+
private static JSONObject parseJSONObject(String text) {
2324
return ((null == text || text.isEmpty()) || !isJSONObject(text)) ? null : JSONObject.class.cast(parseJSON(text));
2425
}
2526

src/ws/http/json/JSON.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/ws/http/test/TestCase.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import ws.http.Request;
66
import ws.http.Response;
7-
import ws.http.json.JSON;
7+
import ws.http.doc.json.JSON;
8+
import ws.http.doc.json.JSONArray;
9+
import ws.http.doc.json.JSONObject;
810

911
import java.util.logging.*;
1012

@@ -16,8 +18,23 @@ public static void main(String[] args) throws IOException {
1618
TestCase obj = new TestCase();
1719
// obj.testGet();
1820
// obj.testPost();
21+
obj.testJson();
1922

23+
}
24+
25+
public void testJson()
26+
{
2027
logger.info( JSON.toJSON(null) );
28+
// String json = "{\"account_id\":\"121\",\"channel\":\"ycb\",\"domain\":\"183.131.145.124\",\"port\":\"80\",\"request_id\":\"e54af3f3-d915-4524-8805-3108d78a2220\",\"request_time\":\"1473833813956\",\"timestamp\":1474251393,\"sign\":\"6905d6e800b8bfed60ca02efbe404abb\"}";
29+
// JSONObject jo = (JSONObject) JSON.parseJSON(json);
30+
// System.out.println(jo.getStringValue("channel"));
31+
// logger.info(jo.getStringValue("channel"));
32+
// logger.info(jo.toString());
33+
34+
Object jo = JSON.parseJSON("[{\"a\":\"21\"}]");
35+
36+
System.out.println(jo instanceof JSONObject);
37+
2138
}
2239

2340
public void testGet() throws IOException

0 commit comments

Comments
 (0)