@@ -643,11 +643,13 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
643643
644644
645645 //key[]:{Table:{}}中key equals Table时 提取Table
646- boolean isContainer = true ;
647646 int index = name == null ? -1 : name .lastIndexOf ("[]" );
648- String table = index <= 0 ? null : Pair .parseEntry (name .substring (0 , index ), true ).getKey ();
649- if (JSONRequest .isTableKey (table ) && request .containsKey (table )) {
650- isContainer = false ;
647+ String childPath = index <= 0 ? null : Pair .parseEntry (name .substring (0 , index ), true ).getKey (); // Table-key1-key2...
648+
649+ //判断第一个key,即Table是否存在,如果存在就提取
650+ String [] childKeys = StringUtil .split (childPath , "-" , false );
651+ if (childKeys == null || childKeys .length <= 0 || request .containsKey (childKeys [0 ]) == false ) {
652+ childKeys = null ;
651653 }
652654
653655
@@ -662,7 +664,7 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
662664 break ;
663665 }
664666 //key[]:{Table:{}}中key equals Table时 提取Table
665- response .add (isContainer ? parent : parent . getJSONObject ( table ) );
667+ response .add (getValue ( parent , childKeys )); //null有意义
666668 }
667669 //Table>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
668670
@@ -676,6 +678,29 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
676678 }
677679
678680
681+ /**根据路径取值
682+ * @param parent
683+ * @param pathKeys
684+ * @return
685+ */
686+ private static Object getValue (JSONObject parent , String [] pathKeys ) {
687+ if (parent == null || pathKeys == null || pathKeys .length <= 0 ) {
688+ Log .w (TAG , "getChild parent == null || pathKeys == null || pathKeys.length <= 0 >> return parent;" );
689+ return parent ;
690+ }
691+
692+ //逐层到达child的直接容器JSONObject parent
693+ final int last = pathKeys .length - 1 ;
694+ for (int i = 0 ; i < last ; i ++) {//一步一步到达指定位置
695+ if (parent == null ) {//不存在或路径错误(中间的key对应value不是JSONObject)
696+ break ;
697+ }
698+ parent = getJSONObject (parent , pathKeys [i ]);
699+ }
700+
701+ return parent == null ? null : parent .get (pathKeys [last ]);
702+ }
703+
679704
680705 /**获取被依赖引用的key的路径, 实时替换[] -> []/i
681706 * @param parentPath
0 commit comments