N
N
Nikita Mikhailenko2015-03-03 12:07:58
Android
Nikita Mikhailenko, 2015-03-03 12:07:58

How to parse non-trivial json (java)?

There is a large and complex JSON object.
Approximate view:

{
    "some_field": 123,
    "some_arr": [
        {
            "field 1": 123,
            "field 2": "abc",
            "field 3": {...},
            "field 4": "def",
            "tags": {
                "some tag title 1": {...},
                "some tag title 2": {...},
                "some tag title 3": {...}
            },
            ...
        },
        ...
    ]
}

The essence of the question : how to parse "tags" into an array? Those. as a result, there should be an ordinary object describing the represented entity, in which one of the fields is an array. In the role of the key - the name of the tag (for each tag is unique, this is the problem), in the role of the value - a normal object. I heard about dynamic keys, but in the examples that I saw, the structures are much simpler and you can get by with Map> map.
Or at least write this "array" of tags as a string, and then parse it as a separate object.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Mikhailenko, 2015-03-03
@SpiritOfDarkDragon

Everything was solved quite simply, I added a field to the gson object:

@SerializedName("tags")
public Map<String,gsonTag> tag;

It was parsed into a map, with which you can already work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question