Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 Android 活动中,我通过包含用户名的 HTTP 获取 JSONArray。数组如下所示:
[{"username":"Julia"},{"username":"Anja"},{"username":"Hans"},{"username":"Sophia"},{"username":"Sarah"}]
如果给定的用户名已经存在,我想检查 Android Activity。
最有效的方法是什么?还是我必须遍历整个数组?
使用简单的字符串函数/方法,如
private boolean userexists(JSONArray jsonArray, String usernameToFind){ return jsonArray.toString().contains("\"username\":\""+usernameToFind+"\""); }