Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

swiftでjson取得

More than 5 years have passed since last update.

とりあえず1階層目の値をDictionaryにして取り出す。ボタンのクリックイベントに実装。

ViewController.swift
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textview: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func button1(sender: AnyObject) {


        //
        let URL = NSURL(string: "http://www.bluecode.jp/test/stock/price.php")

        let jsonData :NSData = NSData(contentsOfURL: URL)
        let json :Dictionary = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: nil) as NSDictionary

        var price:String

        price = json["price"] as NSString

        textview.text = price


    }

}
zaburo
こんにちは。自分用のメモをだらだら公開しています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away