Skip to content

Commit b0a2870

Browse files
committed
APIJSONLibrary新增对tag和version的封装,优化注释和代码
1 parent 64e25e6 commit b0a2870

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@
2525
*/
2626
public class JSONObject extends com.alibaba.fastjson.JSONObject {
2727
private static final long serialVersionUID = 1L;
28-
28+
2929
private static final String TAG = "JSONObject";
3030

31-
31+
3232
/**ordered
3333
*/
3434
public JSONObject() {
3535
super(true);
3636
}
3737
/**transfer Object to JSONObject
3838
* @param object
39-
* @see {@link #JSONObject(Object, boolean)}
39+
* @see {@link #JSONObject(Object)}
4040
*/
4141
public JSONObject(Object object) {
4242
this(toJSONString(object));
4343
}
4444
/**parse JSONObject with JSON String
4545
* @param json
46-
* @see {@link #JSONObject(String, boolean)}
46+
* @see {@link #JSONObject(String)}
4747
*/
4848
public JSONObject(String json) {
4949
this(parseObject(json));
5050
}
5151
/**transfer com.alibaba.fastjson.JSONObject to JSONObject
5252
* @param object
53-
* @see {@link #putsAll(com.alibaba.fastjson.JSONObject)}
53+
* @see {@link #putsAll(Map<? extends String, ? extends Object>)}
5454
*/
5555
public JSONObject(com.alibaba.fastjson.JSONObject object) {
5656
this();
@@ -82,7 +82,7 @@ public static boolean isTableKey(String key) {
8282

8383
//JSONObject内关键词 key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
8484

85-
85+
8686
public static final String KEY_ID = "id";
8787
public static final String KEY_ID_IN = KEY_ID + "{}";
8888

@@ -100,15 +100,15 @@ public JSONObject setId(Long id) {
100100
public JSONObject setIdIn(List<Object> list) {
101101
return puts(KEY_ID_IN, list);
102102
}
103-
104-
103+
104+
105105
//@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<<
106106
public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限
107107
public static final String KEY_CONDITION = "@condition"; //条件 TODO 用 @where& @where| @where! 替代?
108108
public static final String KEY_TRY = "@try"; //尝试,忽略异常
109109
public static final String KEY_DROP = "@drop"; //丢弃,不返回
110110
public static final String KEY_CORRECT = "@correct"; //字段校正
111-
111+
112112
public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明
113113
public static final String KEY_ABOUT = "@about"; //关于,返回数据库表的信息,包括表说明和字段说明
114114
public static final String KEY_COLUMN = "@column"; //查询的Table字段或SQL函数
@@ -125,32 +125,32 @@ public JSONObject setIdIn(List<Object> list) {
125125
public JSONObject setRole(String role) {
126126
return puts(KEY_ROLE, role);
127127
}
128-
128+
129129
/**set try, ignore exceptions
130130
* @param tri
131131
* @return this
132132
*/
133133
public JSONObject setTry(boolean tri) {
134134
return puts(KEY_TRY, tri);
135135
}
136-
136+
137137
/**set drop, data dropped will not return
138138
* @param drop
139139
* @return this
140140
*/
141141
public JSONObject setDrop(boolean drop) {
142142
return puts(KEY_DROP, drop);
143143
}
144-
144+
145145
/**set correct, correct keys to target ones
146146
* @param correct Map{originKey, [posibleKeys]}, posibleKey之间用 , 隔开
147147
* @return this
148148
*/
149149
public JSONObject setCorrect(Map<String, String> correct) {
150150
return puts(KEY_CORRECT, correct);
151151
}
152-
153-
152+
153+
154154

155155
/**set schema where table was puts
156156
* @param schema
@@ -300,10 +300,10 @@ public JSONObject putsSearch(String key, String value, int type) {
300300

301301
//Request >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
302302

303-
303+
304304

305305
/**puts key-value in object into this
306-
* @param object
306+
* @param map
307307
* @return this
308308
*/
309309
public JSONObject putsAll(Map<? extends String, ? extends Object> map) {
@@ -318,28 +318,28 @@ public void putAll(Map<? extends String, ? extends Object> map) {
318318
}
319319

320320

321-
321+
322322
/**put and return this
323323
* @param value must be annotated by {@link MethodAccess}
324-
* @return {@link #puts(String, boolean)}
324+
* @return {@link #puts(String, Object)}
325325
*/
326326
public JSONObject puts(Object value) {
327327
return puts(null, value);
328328
}
329329
/**put and return this
330330
* @param key
331-
* @param value
331+
* @param value
332332
* @return this
333333
* @see {@link #put(String, Object)}
334334
*/
335335
public JSONObject puts(String key, Object value) {
336336
put(key, value);
337337
return this;
338338
}
339-
339+
340340
/**put and return value
341341
* @param value must be annotated by {@link MethodAccess}
342-
* @return {@link #put(String, boolean)}
342+
* @return {@link #put(String, Object)}
343343
*/
344344
public Object put(Object value) {
345345
return put(null, value);
@@ -370,5 +370,5 @@ public Object put(String key, Object value) {
370370
}
371371

372372

373-
373+
374374
}

APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONRequest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ public JSONRequest(String name, Object object) {
4949

5050

5151

52-
52+
5353
public static final String KEY_TAG = "tag";//只在最外层,最外层用JSONRequest
54-
54+
public static final String KEY_VERSION = "version";//只在最外层,最外层用JSONRequest
55+
5556
/**set "tag":tag in outermost layer
5657
* for write operations
5758
* @param tag
@@ -60,6 +61,14 @@ public JSONRequest(String name, Object object) {
6061
public JSONRequest setTag(String tag) {
6162
return puts(KEY_TAG, tag);
6263
}
64+
/**set "version":version in outermost layer
65+
* for write operations
66+
* @param version
67+
* @return
68+
*/
69+
public JSONRequest setVersion(int version) {
70+
return puts(KEY_VERSION, version);
71+
}
6372

6473

6574
//array object <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -103,16 +112,16 @@ public JSONRequest setPage(int page) {
103112
/**create a parent JSONObject named KEY_ARRAY
104113
* @param count
105114
* @param page
106-
* @return {@link #toArray(int, int, boolean)}
115+
* @return {@link #toArray(int, int)}
107116
*/
108117
public JSONRequest toArray(int count, int page) {
109118
return toArray(count, page, null);
110119
}
111-
/**create a parent JSONObject named name+KEY_ARRAY.
120+
/**create a parent JSONObject named name+KEY_ARRAY.
112121
* @param count
113122
* @param page
114123
* @param name
115-
* @return {name+KEY_ARRAY : this}. if needs to be put, use {@link #add(com.alibaba.fastjson.JSONObject)} instead
124+
* @return {name+KEY_ARRAY : this}. if needs to be put, use {@link #putsAll(Map<? extends String, ? extends Object>)} instead
116125
*/
117126
public JSONRequest toArray(int count, int page, String name) {
118127
return new JSONRequest(StringUtil.getString(name) + KEY_ARRAY, this.setCount(count).setPage(page));
@@ -124,7 +133,7 @@ public JSONObject putsAll(Map<? extends String, ? extends Object> map) {
124133
super.putsAll(map);
125134
return this;
126135
}
127-
136+
128137
@Override
129138
public JSONRequest puts(Object value) {
130139
return puts(null, value);

APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONResponse.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
package zuo.biao.apijson;
1616

17-
import java.util.List;
18-
import java.util.Set;
19-
2017
import com.alibaba.fastjson.JSONArray;
2118
import com.alibaba.fastjson.JSONObject;
2219

20+
import java.util.List;
21+
import java.util.Set;
22+
2323
/**parser for response
2424
* @author Lemon
2525
* @see #getObject
@@ -64,7 +64,7 @@ public JSONResponse(JSONObject object) {
6464
public static final String MSG_SUCCEED = "success"; //成功
6565
public static final String MSG_SERVER_ERROR = "Internal Server Error!"; //服务器内部错误
6666

67-
67+
6868
public static final String KEY_CODE = "code";
6969
public static final String KEY_MSG = "msg";
7070
public static final String KEY_ID = "id";
@@ -310,7 +310,7 @@ public static JSONObject format(final JSONObject object) {
310310
Log.i(TAG, "format object == null || object.isEmpty() >> return object;");
311311
return object;
312312
}
313-
JSONObject formatedObject = new JSONObject(true);
313+
JSONObject formatted = new JSONObject(true);
314314

315315
Set<String> set = object.keySet();
316316
if (set != null) {
@@ -320,19 +320,19 @@ public static JSONObject format(final JSONObject object) {
320320
value = object.get(key);
321321

322322
if (value instanceof JSONArray) {//JSONArray,遍历来format内部项
323-
formatedObject.put(replaceArray(key), format((JSONArray) value));
323+
formatted.put(replaceArray(key), format((JSONArray) value));
324324
}
325325
else if (value instanceof JSONObject) {//JSONObject,往下一级提取
326-
formatedObject.put(getSimpleName(key), format((JSONObject) value));
326+
formatted.put(getSimpleName(key), format((JSONObject) value));
327327
}
328328
else {//其它Object,直接填充
329-
formatedObject.put(getSimpleName(key), value);
329+
formatted.put(getSimpleName(key), value);
330330
}
331331
}
332332
}
333333

334-
//太长查看不方便,不如debug Log.i(TAG, "format return formatedObject = " + JSON.toJSONString(formatedObject));
335-
return formatedObject;
334+
//太长查看不方便,不如debug Log.i(TAG, "format return formatted = " + JSON.toJSONString(formatted));
335+
return formatted;
336336
}
337337

338338
/**格式化key名称
@@ -345,24 +345,24 @@ public static JSONArray format(final JSONArray array) {
345345
Log.i(TAG, "format array == null || array.isEmpty() >> return array;");
346346
return array;
347347
}
348-
JSONArray formatedArray = new JSONArray();
348+
JSONArray formatted = new JSONArray();
349349

350350
Object value;
351351
for (int i = 0; i < array.size(); i++) {
352352
value = array.get(i);
353353
if (value instanceof JSONArray) {//JSONArray,遍历来format内部项
354-
formatedArray.add(format((JSONArray) value));
354+
formatted.add(format((JSONArray) value));
355355
}
356356
else if (value instanceof JSONObject) {//JSONObject,往下一级提取
357-
formatedArray.add(format((JSONObject) value));
357+
formatted.add(format((JSONObject) value));
358358
}
359359
else {//其它Object,直接填充
360-
formatedArray.add(value);
360+
formatted.add(value);
361361
}
362362
}
363363

364-
//太长查看不方便,不如debug Log.i(TAG, "format return formatedArray = " + JSON.toJSONString(formatedArray));
365-
return formatedArray;
364+
//太长查看不方便,不如debug Log.i(TAG, "format return formatted = " + JSON.toJSONString(formatted));
365+
return formatted;
366366
}
367367

368368
/**替换key+KEY_ARRAY为keyList

0 commit comments

Comments
 (0)