4
4

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.

[Swiftメモ]PlaygroundでJSon使用

Posted at

たのしいSwiftプログラミングを一通り読みました。
忘れる内にメモしよう!

MyPlayground.playground
// Playground - noun: a place where people can play

import Foundation
import XCPlayground

var urlString = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://rss.dailynews.yahoo.co.jp/fc/rss.xml&num=8"
var url = NSURL(string: urlString)!

var task = NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: {data,response,error in
    var dict = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
    var responseData = dict["responseData"] as NSDictionary
    var feed = responseData["feed"] as NSDictionary
    var entries = feed["entries"]as NSArray
    for entry in entries {
        println(entry["title"])
    }
})
task.resume()

XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
出力結果
Optional(米中間選挙の投票開始 焦点は)
Optional(両親殺害 危険ドラッグ使用か)
Optional(犯罪者扱い 予算委で首相激高)
Optional(震災被災児 ぜんそく発症2倍)
Optional(映像 西日本を飛んだ「火球」)
Optional(韓国で日本代表狙う重戦車FW)
Optional(G相川獲りに一岡のトラウマ)
Optional(西川貴教「風」イメージ不満)
4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?