我想用SwiftJSON来处理json,但是我堆叠了。有没有人给我看一下示例代码?
我试着使用这个库。https://github.com/SwiftyJSON/SwiftyJSON
尽管我把json放在了同一个项目中,但我还是出现了错误“没有这样的模块" swiftyJSON "”,所以请改正我的代码,或者向我展示用swiftyJSON库处理来自web的json的示例代码。
下面是我的代码:
import UIKit
import SwiftyJSON // No such module "SwiftyJSON"
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL(string: "http://express.heartrails.com/api/json?method=getPrefectures")
var request = NSURLRequest(URL: url!)
var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)
var json = NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: nil) as NSDictionary
var hoge = JSON(data)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
下面是我的Xcode截图
https://stackoverflow.com/questions/26754481
复制相似问题