I have got a problem using JSON parser in an android application. I'm starting with this platform, and would like to:
- get some values (different types) from a JSON API
- init a custom class with theses values easily
So, in the iOS application, I made it with a NSDictionnary to set the values to my class. Is it possible to do a such thing in Java ?
I have my User class :
public class User {
protected String id;
protected GregorianCalendar registredAt;
protected String username;
protected String email;
protected Integer score;
protected Integer bonus;
protected Integer sessionsOpened;
protected Integer sessionsWon;
protected Team team;
protected String avatar;
}
Of course I could create a big constructor with every values...
public User(String id, GregorianCalendar registredAt, String username, String email, Integer score, Integer bonus, Integer sessionsOpened, Integer sessionsWon, Team team, String avatar) {
this.id = id;
this.registredAt = registredAt;
...
}
But, to do it, I must manage my JSONObject before to init my User class... What I would do is to initialize this class with the an array of multi-typed values that I could get from the JSONObject... ( Convert Json Array to normal Java Array )
Is it possible ? What is the best method to get a clean array from a JSONObject or JSONArray ?
If it is not possible, another way could be to create the User directly with the JSONObject...
public User(JSONObject attributes) {
}
But I would prefer the java array if that is possible.
Thank you in advance, Bobby.