Skip to content

Commit

Permalink
Server:新增 formate: Boolean,可将[]等有特殊字符的key转为list等常规的key,方便前端解析
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Sep 9, 2018
1 parent 93d4ab1 commit e482237
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public JSONRequest(String name, Object object) {

public static final String KEY_TAG = "tag";//只在最外层,最外层用JSONRequest
public static final String KEY_VERSION = "version";//只在最外层,最外层用JSONRequest
public static final String KEY_FORMAT = "format";//只在最外层,最外层用JSONRequest

/**set "tag":tag in outermost layer
* for write operations
Expand All @@ -71,6 +72,14 @@ public JSONRequest setTag(String tag) {
public JSONRequest setVersion(String version) {
return puts(KEY_VERSION, version);
}
/**set "format":format in outermost layer
* for format APIJSON special keys to normal keys of response
* @param version
* @return
*/
public JSONRequest setFormat(Boolean format) {
return puts(KEY_FORMAT, format);
}


//array object <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public AbstractParser setGlobleDatabase(String globleDatabase) {
this.globleDatabase = globleDatabase;
return this;
}
protected boolean globleFormat;
public AbstractParser setGlobleFormat(Boolean globleFormat) {
this.globleFormat = globleFormat;
return this;
}

@Override
public boolean isNoVerify() {
Expand Down Expand Up @@ -265,7 +270,10 @@ public JSONObject parseResponse(JSONObject request) {

try {
setGlobleDatabase(requestObject.getString(JSONRequest.KEY_DATABASE));
setGlobleFormat(requestObject.getBooleanValue(JSONRequest.KEY_FORMAT));

requestObject.remove(JSONRequest.KEY_DATABASE);
requestObject.remove(JSONRequest.KEY_FORMAT);
} catch (Exception e) {
return extendErrorResult(requestObject, e);
}
Expand Down Expand Up @@ -306,7 +314,7 @@ public JSONObject parseResponse(JSONObject request) {
Log.d(TAG, "parseResponse endTime = " + endTime + "; duration = " + (endTime - startTime)
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\n");

return requestObject;
return globleFormat ? new JSONResponse(requestObject) : requestObject;
}


Expand Down

0 comments on commit e482237

Please sign in to comment.