如何解析这个JSON数据在迅速
问题描述:
我在解析从Web服务器的JSON数据时遇到问题。如果有人能帮助我,我会非常感激。我在iOS应用程序中使用了swift。任何参考也会有很大的帮助。如何解析这个JSON数据在迅速
[
{
"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
答
我想用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
}
}
}
我看到一个字典数组(可以解析为自定义对象)。你有什么尝试? – Larme
您可以在网上找到JSON教程。随着Swift 4,它更容易。不过,我总是喜欢SwiftyJSON。这里是链接https://github.com/SwiftyJSON/SwiftyJSON –