Libgdx - Tiled Map object properties

I’m having a bit of trouble with trying to iterate through the list of keys provided by Libgdx’s MapObject class. As I’m trying to iterate through them, I only receive the data for the first item in the list. Here’s what I’ve got.

MapProperties p = o.getProperties();
while(p.getKeys().hasNext()){
	String s = p.getKeys().next();
	System.out.println(s);
}

All I’m getting is the name of the first key, x, over and over. Any help would be great.

getKeys() returns an iterator which you need to use to access the collection. In the code you posted every call to getKeys() is returning a new iterator and is why you are only getting the first key and why that loop won’t terminate.
Try:


for (String key : o.getProperties().getKeys())
{
   System.out.println(key);
}

or 

for (Iterator<String> iter = o.getProperties().getKeys(); iter.hasNext();)
{
   System.out.println(iter.next());
}

Since it’s a java.util.Iterator returned you can use the top enhanced for loop.