class VIEwController: UIVIEwController { @IBOutlet weak var mynameLabel: UILabel! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib. let manager = AFhttpRequestoperationManager() manager.GET( "https://query.yahooAPIs.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22)&format=Json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=",parameters: nil,success: { (operation: AFhttpRequestoperation!,responSEObject: AnyObject!) in println("JsON: " + responSEObject.description) //How to access and print indivIDual fIElds? },failure: { (operation: AFhttpRequestoperation!,error: NSError!) in println("Error: " + error.localizedDescription) }) } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. }}解决方法 您可以只导航嵌套字典的结构,可能是这样的:
manager.GET( "https://query.yahooAPIs.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22)&format=Json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=",success: { operation,responSEObject in if let quote = responSEObject?.objectForKey("query")?.objectForKey("results")?.objectForKey("quote") as? NSDictionary { let symbol = quote.objectForKey("Symbol") as? String let lastTradePriceOnly = quote.objectForKey("LastTradePriceOnly") as? String println("results: \(symbol) @ \(lastTradePriceOnly)") } else { println("no quote") } },failure: { operation,error in println("Error: " + error.localizedDescription) })总结
以上是内存溢出为你收集整理的使用Swift从AFNetworking访问JSON数据全部内容,希望文章能够帮你解决使用Swift从AFNetworking访问JSON数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)