我有一个项目,轮询一个返回JSON格式值的URL.有什么建议是什么最好的方法来解析我的iOS应用程序的结果?
也可以简单解析一下
var data = NSData(contentsOfURL: NSURL(string: "http://api.androidhive.info/contacts/")!)
var parcedData : NSMutableDictionary = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments, error: nil) as! NSMutableDictionary
print(parceData)
Run Code Online (Sandbox Code Playgroud)
还有很多其他方法可以做到这一点。
Alamofire.request(.GET, url, parameters: parameters)
.responseJSON { (req, res, json, error) in
if(error != nil) {
NSLog("Error: \(error)")
println(req)
println(res)
}
else {
NSLog("Success: \(url)")
var json = JSON(json!)
}
}
Run Code Online (Sandbox Code Playgroud)