-1

I'm having a problem while parsing json data from a web server. If anyone can help me with this, I would be very greatful. I'm using swift in an iOS application. Any references would be of great help as well.

[
{
    "0": "M26177M21MUG",
    "1": "Imbwa yigisha umwana gukambakamba",
    "2": "147746956612e34",
    "3": "2016/10/26",
    "4": "Amazing Video",
    "5": "2016-10-26",
    "videokey": "M26177M21MUG",
    "title": "Imbwa yigisha umwana gukambakamba",
    "file_name": "147746956612e34",
    "file_directory": "2016/10/26",
    "description": "Amazing Video",
    "datecreated": "2016-10-26"
},
{
    "0": "HDYBX1NOBBU7",
    "1": "KIGALI NZIZA 2016 2040",
    "2": "1477409119f676f",
    "3": "2016/10/25",
    "4": "KIGALI NZIZA 2016 2040",
    "5": "2016-10-25",
    "videokey": "HDYBX1NOBBU7",
    "title": "KIGALI NZIZA 2016 2040",
    "file_name": "1477409119f676f",
    "file_directory": "2016/10/25",
    "description": "KIGALI NZIZA 2016 2040",
    "datecreated": "2016-10-25"
},
{
    "0": "6ANO5UXHAD76",
    "1": "Umugabo yigishije imbwa ye gusenga mbere yo kurya",
    "2": "147746949813fd9",
    "3": "2016/10/26",
    "4": "NGWINO by KNC New Rwandan music 2013",
    "5": "2016-10-26",
    "videokey": "6ANO5UXHAD76",
    "title": "Umugabo yigishije imbwa ye gusenga mbere yo kurya",
    "file_name": "147746949813fd9",
    "file_directory": "2016/10/26",
    "description": "NGWINO by KNC New Rwandan music 2013",
    "datecreated": "2016-10-26"
}]

The link to where I'm fetching the the data is:

http://marieadelaideschool.rw/stream/api/vod.php
LarryF
  • 4,925
  • 4
  • 32
  • 40
  • I see an array of dictionary (that could be parsed into a custom object). What have you tried? – Larme Oct 17 '17 at 14:10
  • You can find JSON tutorials all over the web. With Swift 4, it’s even easier. Nevertheless, I always like SwiftyJSON. Here is the link https://github.com/SwiftyJSON/SwiftyJSON – Matthew Bradshaw Oct 17 '17 at 14:20

1 Answers1

2

I think this sample function using Alamofire will helpful for you...

func callApi()
{
    Alamofire.request(.GET, "http://marieadelaideschool.rw/stream/api/vod.php", encoding: .JSON).responseJSON
        {
            response in switch response.2
            {
            case .Success(let JSON):
                print(JSON)
                let responseData = JSON as! NSArray
                for i in responseData
                {
                    let object = i as! NSDictionary
                    let title = object["title"]
                    print(title!)
                }
                break
            case .Failure(let error):
                print("Request failed with error: \(error)")
                break
            }

    }

}
Zee
  • 327
  • 1
  • 8