Java_遍历获取json数据的所有key值
1 public static void getJsonKey(Object obj,String listname){ 2 if(obj instanceof JSONObject){ 3 for (Map.Entry<String, Object> entry : ((JSONObject) obj).entrySet()) { 4 System.out.println(listname+":"+entry.getKey()); 5 if(!(entry.getValue() instanceof String)){ 6 getJsonKey(entry.getValue(),entry.getKey()); 7 } 8 } 9 } 10 if(obj instanceof JSONArray){ 11 JSONArray jsonArray = (JSONArray) obj; 12 for (int i = 0;i < jsonArray.size();i++){ 13 getJsonKey(jsonArray.get(i),listname); 14 } 15 } 16 }