我在Swift2中編寫了自己的函數來解析JSON。解析JSON後,從我的應用程序中的tableView
中顯示從JSON中提取的數據列表。我試圖弄清楚如何按字母順序顯示這些數據。我認爲這需要在函數中調用的append方法之前發生。我想這應該是一個sort
函數,但我一直無法弄清Swift2中正確的排序函數,它會正確執行。任何幫助,我可以得到讚賞! 這裏是我的parseJSON功能:swift:從JSON中解析Alphabetiz數據
func parseJSON(){
do{
let data = NSData(contentsOfURL: NSURL(string: "https://jsonblob.com/api/jsonBlob/580d0ccce4b0bcac9f837fbe")!)
let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
for anItem in jsonResult as! [Dictionary<String, AnyObject>]{
let mifiName2 = anItem["name"] as! String
let mifiId = anItem["employeeId"] as! Int
let newName = Name(mifiName: mifiName2, mifiId: mifiId)
nameOfMifi.append(newName)
//print("Name: \(newName)")
}
}
catch let error as NSError{
print(error.debugDescription)
}
}
** **從來沒有從與同步法服務器負載數據'NSData的(contentsOfURL:'和'MutableContainers'是沒用的斯威夫特 – vadian