我写了下面的代码
List<UserDetails> getUserList(String Json){
try {
JSONObject jsonObject = new JSONObject(Json);
int myname = jsonObject.getInt("itemsPerPage");
System.out.println(myname);
JSONArray jsonarray = (JSONArray) jsonObject.get("list");
System.out.println(jsonarray.length());
if(null != jsonarray && jsonarray.length() == 25){
RestClient restClient = new RestClient();
URL= someurl;
checkValue="USERDETAILS";
startIndex += 25;
String jsonResult = restClient.postJiveUsersData(URL,restUserName,restPassword);
if(null != jsonResult) {
getUserList(jsonResult);
}
}
System.out.println("User List size::" +userDetailsList.size());
return userDetailsList;
执行上述&#34;用户列表大小&#34;不止一次打印。我可以知道原因,有没有办法避免多次打印它。
提前帮助。
此致 Narasimha Reddy P
答案 0 :(得分:3)
由于您的getUserList
方法正在调用自身,因此打印的次数不止一次,因此System.out.println("User List size::" +userDetailsList.size());
会多次执行。