@@ -285,8 +285,9 @@ public JSONArray toArray(String className) {
285285 return toArray (this , className );
286286 }
287287 /**
288+ * array.set(index, isContainer ? value : value.getJSONObject(className));
288289 * @param arrayObject
289- * @param className
290+ * @param className className.isEmpty() == false && value.containsKey(className) >> isContainer = true;
290291 * @return
291292 */
292293 public static JSONArray toArray (JSONObject arrayObject , String className ) {
@@ -357,28 +358,32 @@ public static JSONObject format(final JSONObject response) {
357358
358359 Set <String > set = response .keySet ();
359360 if (set != null ) {
361+
360362 Object value ;
361363 String arrayKey ;
362364 for (String key : set ) {
363365 value = response .get (key );
366+
364367 if (value instanceof JSONArray ) {//转化JSONArray内部的APIJSON Array
365- transferredObject .put (key , format ((JSONArray ) value ));
368+ transferredObject .put (getSimpleName ( key ) , format ((JSONArray ) value ));
366369 } else if (value instanceof JSONObject ) {//APIJSON Array转为常规JSONArray
367370 if (isArrayKey (key )) {//APIJSON Array转为常规JSONArray
368371 arrayKey = key .substring (0 , key .indexOf (KEY_ARRAY ));
369- transferredObject .put (getArrayKey (arrayKey ), format (toArray ((JSONObject ) value , arrayKey )));
372+ transferredObject .put (getArrayKey (getSimpleName (arrayKey ))
373+ , format (toArray ((JSONObject ) value , arrayKey )));//需要将name:alias传至toArray
370374 } else {//常规JSONObject,往下一级提取
371- transferredObject .put (key , format ((JSONObject ) value ));
375+ transferredObject .put (getSimpleName ( key ) , format ((JSONObject ) value ));
372376 }
373377 } else {//其它Object,直接填充
374- transferredObject .put (key , value );
378+ transferredObject .put (getSimpleName ( key ) , value );
375379 }
376380 }
377381 }
378382
379383 Log .i (TAG , "format return transferredObject = " + JSON .toJSONString (transferredObject ));
380384 return transferredObject ;
381385 }
386+
382387 /**
383388 * @param responseArray
384389 * @return
@@ -409,13 +414,13 @@ public static JSONArray format(final JSONArray responseArray) {
409414
410415 /**替换key+KEY_ARRAY为keyList
411416 * @param key
412- * @return isArrayKey(key) ? getArrayKey(...) : key
417+ * @return getSimpleName( isArrayKey(key) ? getArrayKey(...) : key) {@link #getSimpleName(String)}
413418 */
414419 public static String replaceArray (String key ) {
415420 if (isArrayKey (key )) {
416- return getArrayKey (key .substring (0 , key .indexOf (KEY_ARRAY )));
421+ key = getArrayKey (key .substring (0 , key .indexOf (KEY_ARRAY )));
417422 }
418- return key ;
423+ return getSimpleName ( key ) ;
419424 }
420425 /**获取列表变量名
421426 * @param key => StringUtil.getNoBlankString(key)
@@ -433,5 +438,19 @@ public static String getArrayKey(String key) {
433438 }
434439 return key + "List" ;
435440 }
441+
442+ /**获取简单名称
443+ * @param fullName name 或 name:alias
444+ * @return name > name; name:alias > alias
445+ */
446+ public static String getSimpleName (String fullName ) {
447+ //key:alias -> alias; key:alias[] -> alias[]
448+ int index = fullName == null ? -1 : fullName .indexOf (":" );
449+ if (index >= 0 ) {
450+ fullName = fullName .substring (index + 1 );
451+ }
452+ return fullName ;
453+ }
454+
436455
437456}
0 commit comments