I would like to handle json with SwiftJSON, but I stacked.
Does anyone show me example code?
I tried to use this library.
https://github.com/SwiftyJSON/SwiftyJSON
Although I placed SwiftyJSON.swift in the same project, I have error "No such module "SwiftyJSON""
So correct my code or show me example code handling json from web with swiftyJSON lib.
Here is my code:
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.
}
}
Here is my Xcode capture
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…