-1

我在解析来自 Web 服务器的 json 数据时遇到问题。如果有人可以帮助我,我将非常感激。我在 iOS 应用程序中使用 swift。任何参考资料也会有很大帮助。

[
{
    "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"
}]

我获取数据的链接是:

http://marieadelaideschool.rw/stream/api/vod.php
4

1 回答 1

2

我认为这个使用 Alamofire 的示例函数会对你有所帮助......

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
            }

    }

}
于 2017-10-17T14:25:24.713 回答