0

I am new to GSON and thus far have been successfully using it in my project. This JSON has been problematic for me...

 { "status": "6000", "action": "getProducts", "categories": { "type1": [ { "name": "name1", "subtitle": "subtitle1" }, { "name": "name2", "subtitle": "subtitle2" } ], "type2": [ { "name": "name3", "subtitle": "name3" } ] } } 

What's throwing me off is that I don't want to have to know the names "type1", "type2", etc. They will be used to dynamically populate a list view. What should my GSON objects looks like? or should my JSON be refactored? I have full control over the backend.

1 Answer 1

3

You could do it like this

... private Map<String, YourObject[]> categories; ... 

or

... private Map<String, List<YourObject>> categories; ... 

and then you would call categories.keySet() to get set of type1, type2, ...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.