"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"
}
]
},
Asked
Active
Viewed 105 times
-2

Phantômaxx
- 37,901
- 21
- 84
- 115

Muhammad Danish
- 51
- 5
-
3have you at least tried to google something like "parse JSON in Android?" – Derlin Oct 17 '17 at 12:59
-
Ever parsed json before? Create your pojo-models with right members and for android **you can use the gson-library** instead of old javax.rs – LenglBoy Oct 17 '17 at 12:59
-
@LenglBoy its my first time – Muhammad Danish Oct 17 '17 at 13:07
-
while you´re working with android use the gson-Parser. Gson is very simple to use and very comfortable. if you´re working with clear java/javaEE project then use normal java.rs because gson is a 3rd party tool - and overhyped/not nessesarry. – LenglBoy Oct 17 '17 at 13:15
-
@LenglBoy my above given API code can be parsed from gson or not. – Muhammad Danish Oct 17 '17 at 13:19
-
it can. but you need to create the classes and attributes. Here are some examples [gson exapmle](http://www.javacreed.com/simple-gson-example/) – LenglBoy Oct 17 '17 at 13:20
-
@LenglBoy any other easy way of doing this ? – Muhammad Danish Oct 17 '17 at 13:22
-
@LenglBoy i am totally new in android development and this is my university project related. – Muhammad Danish Oct 17 '17 at 13:23
-
http://jsonschema2pojo.org/ paste this json there, select java, JSON, GSON, convert it. Then you will get pojo model classes from where you will easily able to parse your JSON – Zeeshan Sardar Oct 17 '17 at 13:30
1 Answers
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.

LenglBoy
- 1,451
- 1
- 10
- 24