Java - Parse - iterate over ParseObject fields

荒凉一梦 提交于 2020-06-09 06:25:31

问题


Having a ParseObject object how can I loop through its fields and get the name of the field along with the value of it? This would really help me minimize my code.


回答1:


Hmm, ParseObject contains key-value pairs, and I think you can't iterate though it. But. I found something called .keySet() method of ParseObject. It returns ... well, the set of keys (excluding createdAt, updatedAt, authData, or objectId). I think you can convert it into an array and iterate trhough it?

Something like this:

Set<String> keySet = parseObject.keySet();
String[] parseKeys = keySet.toArray(new String[keySet.size()]);
for (String key : parseKeys) {
    String parseValue = parseObject.get(key);        
    //do whatever you want
 }


来源:https://stackoverflow.com/questions/33246163/java-parse-iterate-over-parseobject-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!