21
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift2.0 JSONパース

Last updated at Posted at 2015-11-09

#Swift2.0のソースコード

ViewController.swift
import UIKit

class ViewController: UIViewController {

    
    private var json:NSDictionary!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        getJson()
    }
    
    func getJson() {
        
        let URL:NSURL = NSURL(string: "http://express.heartrails.com/api/json?method=getStations&name=%E6%96%B0%E5%AE%BF")!
        let jsonData :NSData = NSData(contentsOfURL: URL)!
        
        do {
            json = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) as! NSDictionary
        } catch  {
            // エラー処理
        }
        
        let response:NSDictionary = json.objectForKey("response") as! NSDictionary
        let station:NSArray = response.objectForKey("station") as! NSArray
        
        
        for var i=0 ; i < station.count ; i++ {
            print(station[i].objectForKey("prefecture") as! NSString)
        }
    }
}

#iOS9での非SSL/TLS通信ができない問題の対応
swift.png

赤枠の部分をinfo.plistに追加する。

21
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?