Answer the question
In order to leave comments, you need to log in
Java Iterator, what am I doing wrong?
@Override
public Map<Class, Object> JSONFormatStringSeparator(JSONObject jsonObject) {
Iterator<String> keys = jsonObject.keys(); // ключи которые я передаю в 2 метода.
while (keys.hasNext()){
String key = keys.next();
System.out.print(": "+key); // выводятся все!
}
String value = valueChecker(keys,jsonObject);
if(value!=null) {
switch (value) {
case "create-company":
String [] array = {"id","compname","password","email"};
if(keyChecker(keys,array) == array.length){
System.out.println("All found"); // для проверки
Company company = new Company(jsonObject.getLong("id"),jsonObject.getString("compname"),jsonObject.getString("password"),jsonObject.getString("email"));
return objectMapper(Company.class,company);
}
}
}
return null;
}
private String valueChecker(Iterator<String> keys,JSONObject jsonObject){
while(keys.hasNext()){
String key = keys.next();
System.out.print(key+":From value checker "); // выводится только formId
if(key.equals("formId")){
return (String)jsonObject.get(key);
}
}
return null;
}
// в данном методе выводится всё кроме formId
private byte keyChecker(Iterator<String>keys,String[]values){
byte index = 0,matches = 0;
while (keys.hasNext()){
String key = keys.next();
System.out.println(key); // вывод на проверку.
if(!(key.equals("formId"))) {
if (key.equals(values[index])) {
matches++;
}
}
index++;
}
return matches;
}
"id":"***",
"compname":"***",
"password":"***",
"email":"***",
"formId":"create-company"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question