func makeGetRequest(){
var url : String = "http://apiairline.sunkhoai.com/api-v2/get-airinfo?ver=2?iata=ALL&direction=ALL"
var request : NSMutableURLRequest = NSMutableURLRequest ()
request.URL = NSURL(string: url)
request.HTTPMethod = "GET"
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
let jsonResult: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary
var _names: NSMutableArray = NSMutableArray()
if (jsonResult != nil) {
// Success
// println(jsonResult)
let dataArray = jsonResult["airinfo_list"] as NSArray;
var _names: NSMutableArray = NSMutableArray()
for item :AnyObject in dataArray{
let obj = item as NSDictionary
_names.addObject(item)
self.TableData = _names
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
} else {
// Failed
println("Failed")
}
})
}如何显示一个对象的所有信息
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell如何显示一个对象的所有信息
if let airinfo_list = TableData[indexPath.row] as? NSDictionary{
var ten = airinfo_list.valueForKey("AirNumberEx") as NSString
cell.textLabel?.text = ten
}
return cell发布于 2016-02-22 12:00:29
如果您只想显示对象中的所有内容,最简单的方法是JSON.stringify(object);。这将转储对象中的所有内容,您可以将其写入控制台或发出警报,无论哪种方法,该方法都会给出一个字符串结果。
最终编辑:忽略我的回答。您的标签已更新,以正确反映您正在使用的语言。由于相似之处,当您需要Objective-C时,我给出了JS答案。正确地标记/解释你的帖子可以帮助社区知道你想要什么。
最终编辑:在浏览完SO之后,这可能是你需要的答案:Objective C Introspection/Reflection
https://stackoverflow.com/questions/35545571
复制相似问题