-2
"sport_events": [
    {
        "id": "sr:match:12606716",
        "scheduled": "2017-09-27T10:00:00+00:00",
        "start_time_tbd": false,
        "status": "closed",
        "tournament_round": {
            "type": "group",
            "number": 1,
            "group": "Gr. 4"
        },
        "season": {
            "id": "sr:season:45960",
            "name": "U17 European Ch.ship QF 17/18",
            "start_date": "2017-09-27",
            "end_date": "2018-04-30",
            "year": "17/18",
            "tournament_id": "sr:tournament:755"
        },
        "tournament": {
            "id": "sr:tournament:755",
            "name": "U17 European Ch.ship QF",
            "sport": {
                "id": "sr:sport:1",
                "name": "Soccer"
            },
            "category": {
                "id": "sr:category:392",
                "name": "International Youth"
            }
        },
        "competitors": [
            {
                "id": "sr:competitor:22646",
                "name": "Russia",
                "country": "Russia",
                "country_code": "RUS",
                "abbreviation": "RUS",
                "qualifier": "home"
            },
            {
                "id": "sr:competitor:22601",
                "name": "Faroe Islands",
                "country": "Faroe Islands",
                "country_code": "FRO",
                "abbreviation": "FRO",
                "qualifier": "away"
            }
        ]
    },
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Add gson to your project by adding this into your build-script.gradle:

dependencies {
    compile 'com.google.code.gson:gson:2.8.2'
}

Now create the classes you need but first correct your json string. I guess you forgot a attributename at the beginning. This is your new best friend: json formatter online

After you corrected your json-string and you´ve created your Wrapper and Pojo model-classes with the needed attributes, you parse the string back into the wrapper-object and with getter/setter you get change/get data out of it.

Gson gson = new GsonBuilder().create();
Wrapper wrap = gson.fromJson(jsonString, Wrapper.class);

Don´t forget try-catch block because there can be many thrown exceptions. Good luck to you.

How-to-for-beginner

LenglBoy
  • 1,451
  • 1
  • 10
  • 24