java - Type check in a Json String -
i wrote method verify types of 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 testing method 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 returns false because of - if(ex instanceof string[]). how can check if array string array?
because
if(ty instanceof string)
and ty being not string
Comments
Post a Comment