Verwandeln Sie API JSON in ein statisches verschachteltes Array innerhalb der AppIOS

Programmierung für iOS
Guest
 Verwandeln Sie API JSON in ein statisches verschachteltes Array innerhalb der App

Post by Guest »

Ich verwende eine API, die bald eingestellt wird, und ich muss sie weiterhin verwenden.
Es ist die ESPN-API, und ich Verwenden Sie es einfach, um eine Liste der Teams zu erhalten. Es ist also in Ordnung, wenn es statisch wird.
Im Moment greife ich also auf die API zu, aber wenn sie die API ausschalten Ich muss die Teams weiterhin in meiner App verfügbar haben.
Unten ist der JSON, wie würde ich ihn auf intelligente Weise in meine App integrieren? (Ich habe Restkit verwendet und die Elemente aus der API in ihrer jeweiligen Tabellenansicht aufgelistet Controller).
Anfrage-URI: http://api.espn.com/v1/sports/?apikey=abcdefg
Antworttext (genug um sich ein Bild zu machen):

Code: Select all

{
"sports": [{
"name": "baseball",
"id": 1,
"uid": "s:1",
"links": {
"api": {
"sports": {
"href": "http://api.espn.com/v1/sports/baseball"
},
"news": {
"href": "http://api.espn.com/v1/sports/baseball/news"
},
"notes": {
"href": "http://api.espn.com/v1/sports/baseball/news/notes"
},
"headlines": {
"href": "http://api.espn.com/v1/sports/baseball/news/headlines"
},
"events": {
"href": "http://api.espn.com/v1/sports/baseball/events"
}
}
},
"leagues": [{
"name": "Major League Baseball",
"abbreviation": "mlb",
"id": 10,
"uid": "s:1~l:10",
"groupId": 9,
"shortName": "MLB",
"season": {
"year": 2014,
"type": 2,
"description": "regular",
"startDate": "2014-03-21T07:00:00Z",
"endDate": "2014-09-30T06:59:59Z"
},
"week": {
"number": 22,
"startDate": "2014-08-15T07:00:00Z",
"endDate": "2014-08-22T06:59:00Z"
}
}, {
"name": "Men's College Baseball",
"abbreviation": "college-baseball",
"id": 14,
"groupId": 14,
"shortName": "NCAA Men's Baseball"
}]
}, {
"name": "basketball",
"id": 40,
"uid": "s:40",
"links": {
"api": {
"sports": {
"href": "http://api.espn.com/v1/sports/basketball"
},
"news": {
"href": "http://api.espn.com/v1/sports/basketball/news"
},
"notes": {
"href": "http://api.espn.com/v1/sports/basketball/news/notes"
},
"headlines": {
"href": "http://api.espn.com/v1/sports/basketball/news/headlines"
},
"events": {
"href": "http://api.espn.com/v1/sports/basketball/events"
}
}
},
"leagues": [{
"name": "National Basketball Assoc.",
"abbreviation": "nba",
"id": 46,
"uid": "s:40~l:46",
"groupId": 7,
"shortName": "NBA",
"season": {
"year": 2014,
"type": 4,
"description": "offseason",
"startDate": "2014-07-01T07:00:00Z",
"endDate": "2014-10-04T06:59:59Z"
},
"week": {
"number": 10,
"startDate":  "2014-06-21T07:00:00Z",
"endDate": "2014-06-30T06:59:00Z"
}
}, {
"name": "Women's National Basketball Assoc.",
"abbreviation": "wnba",
"id": 59,
"uid": "s:40~l:59",
"groupId": 3,
"shortName": "WNBA",
"season": {
"year": 2014,
"type": 3,
"description": "post",
"startDate": "2014-08-18T07:00:00Z",
"endDate": "2014-10-21T06:59:59Z"
},
"week": {
"number": 3,
"startDate": "2012-10-09T07:00:00Z",
"endDate": "2012-10-16T06:59:00Z"
}
}, {
"name": "NCAA Basketball",
"abbreviation": "mens-college-basketball",
"id": 41,
"uid": "s:40~l:41",
"groupId": 52,
"shortName": "NCAA Basketball",
"season": {
"year": 2015,
"type": 1,
"description": "pre",
"startDate": "2014-07-01T07:00:00Z",
"endDate": "2014-11-07T07:59:59Z"
},
"week": {
"number": 4,
"startDate": "2014-04-07T07:00:00Z",
"endDate": "2014-04-14T06:59:00Z"
}
}, {
"name": "NCAA Women's Basketball",
"abbreviation": "womens-college-basketball",
"id": 54,
"uid": "s:40~l:54",
"groupId": 52,
"shortName": "NCAA Women's Basketball",
"season": {
"year": 2015,
"type": 1,
"description": "pre",
"startDate": "2014-07-01T07:00:00Z",
"endDate": "2014-11-07T07:59:59Z"
},
"week": {
"number": 4,
"startDate": "2014-04-07T07:00:00Z",
"endDate": "2014-04-14T06:59:00Z"
}
}]
}, {
"name": "football",
"id": 20,
"uid": "s:20",
"links": {
"api": {
"sports": {
"href": "http://api.espn.com/v1/sports/football"
},
"news": {
"href": "http://api.espn.com/v1/sports/football/news"
},
"notes": {
"href": "http://api.espn.com/v1/sports/football/news/notes"
},
"headlines": {
"href": "http://api.espn.com/v1/sports/football/news/headlines"
},
"events": {
"href": "http://api.espn.com/v1/sports/football/events"
}
}
},
"leagues": [{
"name": "National Football League",
"abbreviation": "nfl",
"id": 28,
"uid": "s:20~l:28",
"groupId": 9,
"shortName": "NFL",
"season": {
"year": 2014,
"type": 1,
"description": "pre",
"startDate": "2014-07-30T07:00:00Z",
"endDate": "2014-09-03T06:59:59Z"
},
"week": {
"number":  4,
"startDate": "2014-08-20T07:00:00Z",
"endDate": "2014-08-27T06:59:00Z",
"text": "Week 3"
}
}, {
"name": "NCAA Football",
"abbreviation": "college-football",
"id": 23,
"uid": "s:20~l:23",
"groupId": 99,
"shortName": "NCAA Football",
"season": {
"year": 2014,
"type": 2,
"description": "regular",
"startDate": "2014-07-20T07:00:00Z",
"endDate": "2014-12-16T07:59:59Z"
},
"week": {
"number": 1,
"startDate": "2014-08-19T07:00:00Z",
"endDate": "2014-09-02T06:59:00Z",
"text": "Week 1"
}
}]
}, {
"name": "hockey",
"id": 70,
"uid": "s:70",
"links": {
"api": {
"sports": {
"href": "http://api.espn.com/v1/sports/hockey"
},
"news": {
"href": "http://api.espn.com/v1/sports/hockey/news"
},
"notes": {
"href": "http://api.espn.com/v1/sports/hockey/news/notes"
},
"headlines": {
"href": "http://api.espn.com/v1/sports/hockey/news/headlines"
},
"events": {
"href": "http://api.espn.com/v1/sports/hockey/events"
}
}
},
"leagues": [{
"name": "National Hockey League",
"abbreviation": "nhl",
"id": 90,
"uid": "s:70~l:90",
"groupId": 9,
"shortName": "NHL",
"season": {
"year": 2014,
"type": 4,
"description": "offseason",
"startDate": "2014-06-23T07:00:00Z",
"endDate": "2014-09-01T06:59:59Z"
},
Die View-Controller-Sequenz ist Sport --> Ligen --> Teams
Wenn Sie also „Basketball“ ---> „NBA - -> „Miami Heat“.
Wird bei Bedarf zusätzlichen Code veröffentlichen.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post