Last active
August 29, 2015 14:24
-
-
Save satomixx/594acd6aa643fd0ec98d to your computer and use it in GitHub Desktop.
[Swift] AlamofireでApiを叩いて、SwiftyJSONでレスポンスデータを展開する ref: http://qiita.com/tsumekoara/items/9bbb429f41e40c76882c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Alamofire | |
import SwiftyJSON | |
・ | |
・ | |
・ | |
Alamofire.request(.GET, "http://foo.com/api/v1/bar/1", parameters: ["foo": "bar"]) | |
.response { (request, response, data, error) in | |
println(request) | |
println(response) | |
} | |
.responseJSON { (_, _, json_data, _) in | |
println(json_data) | |
let json = JSON(json_data!) | |
println(json) | |
println(json["bar"]) | |
println(json["bar"]["hoge_id"]) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bar" : { | |
"id" : 1, | |
"created_at" : "2015-07-01T12:25:41.438+09:00", | |
"updated_at" : "2015-07-01T12:25:41.438+09:00", | |
"hoge_id" : 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"id" : 1, | |
"created_at" : "2015-07-01T12:25:41.438+09:00", | |
"updated_at" : "2015-07-01T12:25:41.438+09:00", | |
"hoge_id" : 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Optional({ | |
bar = { | |
"created_at" = "2015-07-01T12:25:41.438+09:00"; | |
id = 1; | |
"updated_at" = "2015-07-01T12:25:41.438+09:00"; | |
"hoge_id = 1" | |
}; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<NSMutableURLRequest: 0x7fab3b28b720> { URL: http://foo.com/api/v1/bar/1?foo=bar } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Optional(<NSHTTPURLResponse: 0x7fab38d60bc0> { URL: http://foo.com/api/v1/bar/1?foo=bar } { status code: 200, headers { | |
・ | |
・ | |
"Cache-Control" = "max-age=0, private, must-revalidate"; | |
Connection = "keep-alive"; | |
"Content-Type" = "application/json; charset=utf-8"; | |
・ | |
・ | |
・ | |
} }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment