user7694262
user7694262

Reputation:

JSON array parsing with different types

I am using vk.com API and in one method in response I am getting something like this:

{
    "ts": 1691519416,
    "updates": [
        [
            6,
            2000000024,
            586731
        ],
        [
            4,
            586732,
            8243,
            2000000024,
            1512642885,
            "income message",
            {
                "from": "384574802"
            }
        ]
    ]
}

The problem is I am using Gson and I don't know what type of array I need to use.

For now I have this:

public class Updates {
    public int ts;
    public Update[] updates;
}

I don`t know what to put inside/instead of updates array.

Found a solution, thank you guys for answers. I just needed to use generics and a 2 dimensional array. The code of Updates class:

public class Updates {
    public int ts;
    public <?>[][] updates;
}

Upvotes: 0

Views: 70

Answers (2)

user7694262
user7694262

Reputation:

Just need to create a generic array.

private Object<?>[] json;

Upvotes: 0

0x3d
0x3d

Reputation: 470

You can create your class like:

class Response
{
   Timestamp ts;
   Updates[] updates;
}

And use GSON:

Response response = gson.fromJson(jsonString, Response.class);

Upvotes: 1

Related Questions