什么是在iOS Swift中解析JSON格式的最佳方法?

Alv*_*yes 5 json ios swift

我有一个项目,轮询一个返回JSON格式值的URL.有什么建议是什么最好的方法来解析我的iOS应用程序的结果?

Ash*_*kad 1

也可以简单解析一下

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)

还有很多其他方法可以做到这一点。

您可以将AlamofireSwiftyJSON结合使用

AlamofireSwiftyJSON的片段

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)