tjb
tjb

Reputation: 11728

snakeYAML JAVA: using the object produced

I am attempting to use snakeYAML to load a YAML file into an object in an Android Java Class. How do I access the members of the resulting object?

Yaml yaml = new Yaml();
Object data = yaml.load(questionsStream);
Log.v(TAG2,data.toString());

The output is:

03-07 18:15:55.637: VERBOSE/Q_Engine Load Questions(615): [{Answer=Sun Jun 25 01:00:00 GMT+01:00 1950, ID=8, Meta Info={Main Topics=[Korean War]}, Obscurity=1, Question=When did the Korean War begin?}, etc...

I want to iterate through the list of Maps and access their members by their keywords.

Upvotes: 0

Views: 1668

Answers (2)

user8681
user8681

Reputation:

Replace the second line with:

List<Map<String, Object>> data = (List<Map<String, Object>>) yaml.load(questionsStream);

The Objects from inside the Map can be cast to Maps or Lists and iterated through the same way, depending on the yaml file structure.

Upvotes: 1

Andrey
Andrey

Reputation: 3001

Cast your data to list of Maps and iterate.

Upvotes: 1

Related Questions