I wrote this method to verify the types of a Json String:
public static boolean loginMessageCheck(String json){
boolean ret = false;
JSONObject o = new JSONObject(json);
Object ty = o.get("type");
Object ex = o.get("expansions");
if(ty instanceof String){
if(ex instanceof String[]){
ret = true;
}
}
return ret;
}
So now I am testing the method like this.
public static void main(String[] args){
String[] expansions= {"chat", "test"};
LoginMessage_Client lm = new LoginMessage_Client("login", expansions);
Gson gson = new Gson();
String json = gson.toJson(lm);
System.out.println(loginMessageCheck(json));
}
It always returns false because of - if(ex instanceof String[]). How can I check if this array is a String array?
because
and ty being not a String