Java - Parse - iterate over ParseObject fields

2020-05-02 06:13发布

问题:

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
 }