SwiftyJSONを使ってjsonを扱う
- 作者: 荻原剛志
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2014/12/10
- メディア: 大型本
- この商品を含むブログ (1件) を見る
jsonの扱いにはSwiftyJSONを使ってます。
import UIKit class ViewController2: UIViewController { override func viewDidLoad() { super.viewDidLoad() var url = NSURL(string: "http://webservice.recruit.co.jp/relax/salon/v1?response_reserve=1&count=15&order=3&address=%E9%8A%80%E5%BA%A7&key=d80cc5011c92e61d&format=json") var request = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue.mainQueue(), completionHandler: { (res: NSURLResponse!, data: NSData!, error: NSError!) in let json = JSON(data: data) if let image = json["results"]["salon"][0]["mood"][0]["photo"].stringValue { println(image) } if let caption = json["results"]["salon"][0]["mood"][0]["caption"].stringValue { println(caption) } }) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }