{"id":92,"date":"2015-08-18T00:46:39","date_gmt":"2015-08-18T00:46:39","guid":{"rendered":"http:\/\/blog.lizefield.mobi\/?p=92"},"modified":"2015-08-18T00:46:39","modified_gmt":"2015-08-18T00:46:39","slug":"json%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%97%e3%81%a6%e3%82%bf%e3%83%97%e3%83%abtuple%e3%81%ae%e9%85%8d%e5%88%97%e3%81%ab%e6%a0%bc%e7%b4%8dswift","status":"publish","type":"post","link":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/2015\/08\/18\/json%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%97%e3%81%a6%e3%82%bf%e3%83%97%e3%83%abtuple%e3%81%ae%e9%85%8d%e5%88%97%e3%81%ab%e6%a0%bc%e7%b4%8dswift\/","title":{"rendered":"JSON\u3092\u30d1\u30fc\u30b9\u3057\u3066\u30bf\u30d7\u30eb(tuple)\u306e\u914d\u5217\u306b\u683c\u7d0d(Swift)"},"content":{"rendered":"<p>iOS:8.4<br \/>\nXcode:6.4<br \/>\nSwift:1.2<\/p>\n<p><!--more--><\/p>\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u3069\u4f7f\u308f\u305aJSON\u3092\u30d1\u30fc\u30b9\u3057\u307e\u3059\u3002\u7d50\u679c\u3068\u3057\u3066tuple\u3092\u914d\u5217\u5316\u3057\u305f\u3082\u306e\u306b\u5165\u308c\u307e\u3059\u3002<\/p>\n<pre>func data2arr(data: NSData) {\n    \/\/ tuple array\n    var talks: [(Int, String, String, Int)] = []\n    \/\/ json\n    let json:NSDictionary = NSJSONSerialization.JSONObjectWithData(\n        data,\n        options: NSJSONReadingOptions.AllowFragments,\n        error: nil) as! NSDictionary\n    \/\/ json -&gt; array\n    if let items = json[\"List\"] as? NSArray {\n        for item in items {\n            if let t = item as? NSDictionary {\n                var nid:Int = 0\n                var ntitle:String = \"\"\n                var nupdated:String = \"\"\n                var ncount:Int = 0\n                if let id = t[\"Id\"] as? NSInteger {\n                    nid = id\n                }\n                if let title = t[\"Title\"] as? NSString {\n                    ntitle = title as String\n                }\n                if let updated = t[\"Date\"] as? NSString {\n                    nupdated = updated as String\n                }\n                if let count = t[\"Count\"] as? NSInteger {\n                    ncount = count\n                }\n                let talk = (nid, ntitle, nupdated, ncount)\n                talks.append(talk)\n            }\n        }\n    }\n    for talk in talks {\n        println(\"\\(talk.0),\\(talk.1),\\(talk.2),\\(talk.3)\")\n    }\n}\n<\/pre>\n<p>data\u306fHTTP\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30c7\u30fc\u30bf\u3067\u3059\u3002\u305d\u308c\u3092NSJSONSerialization.JSONObjectWithData\u3067Dictionary\u306b\u3057\u3066\u6271\u3044\u307e\u3059\u3002<br \/>\n\u305d\u308c\u3092JSON\u306e\u914d\u5217\u3067\u3042\u308c\u3070NSArray\u3001\u6587\u5b57\u306a\u3089\u3070NSString\u3001\u6570\u5024\u306a\u3089\u3070NSInteger\u306a\u3069\u3067\u53d6\u308a\u51fa\u3057\u3001\u7d50\u679c\u3092tuple\u306e\u914d\u5217\u306b\u5165\u308c\u3066\u307e\u3059\u3002<br \/>\n\u5f8c\u306ftuple\u306e\u30e9\u30d9\u30eb\u7b49\u3064\u3051\u305f\u308a\u3059\u308c\u3070\u6271\u3044\u3084\u3059\u304f\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS:8.4 Xcode:6.4 Swift:1.2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[43,45,47,66,71],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/92"}],"collection":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":0,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lizefieldwp.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}