I have this output JSON:
{
"id": 42950262095,
"name": "lol",
"players": [
{
"avatar": {
"userId": 25771876384,
"userName": "yhht",
"role": "Leader",
"level": 40,
"league": 0,
"trophies": 1011,
"donatedTroops": 0,
"receivedTroops": 0
}
},
{
"avatar": {
"userId": 146035414262,
"userName": "ari",
"role": "New Member",
"level": 8,
"league": 0,
"trophies": 428,
"donatedTroops": 0,
"receivedTroops": 0
}
},
{
"avatar": {
"userId": 300659467521,
"userName": "cp 221",
"role": "New Member",
"level": 6,
"league": 0,
"trophies": 97,
"donatedTroops": 0,
"receivedTroops": 0
}
}
],
"badge": 13000049,
"status": "Anyone Can Join",
"playerCount": 3,
"score": 767,
"requiredTrophies": 0,
"warsWon": 0,
"warsLost": 0,
"warsTied": 0,
"warFrequency": 0,
"exp": 0,
"level": 1,
"description": "??lol????"
}
But the problem is the players array comes too early and part of the initial details are left out.
This is my code:
public void parseAvatar() throws IOException, JSONException{
Game game = new Game();
game.setId(is.readLong());
game.setName(is.readString());
game.setBadge(is.readInt());
game.setStatus(status(is.readInt()));
game.setPlayerCount(is.readInt());
game.setScore(is.readInt());
game.setRequiredTrophies(is.readInt());
game.setWarsWon(is.readInt());
game.setWarsLost(is.readInt());
game.setWarsTied(is.readInt());
is.readInt();
game.setWarFrequency(is.readInt());
is.readInt();
game.setExp(is.readInt());
game.setLevel(is.readInt());
game.setDescription(is.readString());
is.readInt();
boolean a = is.readBoolean();
if(a){
is.readInt();
is.readInt();
}
int memCount = is.readInt();
/// Members!!
int i = 0;
while(i < memCount){
PlayerAvatar avatar = new PlayerAvatar();
avatar.setUserId(is.readLong());
avatar.setUserName(is.readString());
avatar.setRole(role(is.readInt()));
avatar.setLevel(is.readInt());
avatar.setLeague(is.readInt());
avatar.setTrophies(is.readInt());
avatar.setDonatedTroops(is.readInt());
avatar.setReceivedTroops(is.readInt());
is.readInt();
is.readInt();
is.readLong();
is.readByte();
is.readByte();
is.readLong();
GamePlayer player = new GamePlayer();
player.setAvatar(avatar);
game.addPlayers(player);
i++;
}
json = new Gson().toJson(game);
System.out.println();
}
private String role(int role) {
String memberRole = "";
if(role == 1){
memberRole = "New Member";
}
if(role == 2){
memberRole = "Leader";
}
if(role == 3){
memberRole = "Elder";
}
if(role == 4){
memberRole = "Co Leader";
}
return memberRole;
}
private String status(int statusint) {
String type = null;
if(statusint == 1){
type = "Anyone Can Join";
}
if(statusint == 2){
type = "Invite Only";
}
if(statusint == 3){
type = "Closed";
}
return type;
}
You can find details for the Game, PlayerAvatar and GamePlayer class in this post: https://stackoverflow.com/a/33048622
Does anyone have any idea on how I can get this ordered properly?