mercredi 6 mai 2015

Given the following JSON file display a list of messages grouped by user

I'm able to read a JSON file containing a list of messages and their corresponding authors. The structure of a single message is the following:

JSON

{  
   "created_at":"Thu Apr 30 10:47:49 +0000 2015",
   "id":593728455901990912,
   "user":{  
      "id":12,
      "name":"GiGi",
      "user_date":"Thu May 17 10:47:49 +0000 2010",
   },
}

The Author and Message classes (POJOs) contain the fields that we want to parse and a function toString() that display the fields in a string.

Author

public class Author {

    @SerializedName("id")
    private static long id;

    @SerializedName("created_at")
    private static String user_date;

    private static String name;

    public  String toString() {
        return name + "\n" + id + "\n" + user_date;         
    }

}

Message

public class Message {

    @SerializedName("user")
    Author author;   

    @SerializedName("created_at")
    String date;

    long id;

    public String toString() {
        return id + "\n" + date;        
    }

}

Author is a member class of the Message class and i need to display the messages grouped by user but i don't seem to find an elegant way of doing it.

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire