5
1

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.

スプラトゥーン2のステージ情報を取得してみた

Posted at

今更ながらAlamofireとSwiftyJSONを使用してスプラトゥーン2のステージ情報を取得してみた

AlamofireとSwiftyJSONを入れる

今回はCarthageを利用

Carthageのインストール

$ brew update
$ brew install carthage

Cartfileの編集

Cartfile
github "SwiftyJSON/SwiftyJSON"
github "Alamofire/Alamofire" ~> 4.7

インストール

carthage update --platform ios

iksm_session(Cookie)の取得

下記の方法でiksm_sessionを取得
https://qiita.com/valmet/items/1b3960085a8764778bf0

Alamofireでリクエスト

取得したiksm_sessionを使用してリクエスト

Alamofire.request("https://app.splatoon2.nintendo.net/api/data/stages", method: .get, parameters: nil, encoding: JSONEncoding.default, headers:
            ["cookie": "iksm_session=\(iksmSession)"]).responseJSON { (response) in
                switch response.result {
                case .success(let value):
                    let json = JSON(value)
                    print(json)
                case .failure(let error):
                    print(error)
                }
        }

するとするとこんな感じでjsonが取得できる

{
  "stages" : [
    {
      "id" : "20",
      "name" : "スメーシーワールド",
      "image" : "\/images\/stage\/555c356487ac3edb0088c416e8045576c6b37fcc.png"
    },
    {
      "id" : "16",
      "name" : "モンガラキャンプ場",
      "image" : "\/images\/stage\/e4c4800be9fff23112334b193abb0fdf36e05933.png"
    },
    {
      "id" : "17",
      "image" : "\/images\/stage\/828e49a8414a4bbc0a5da3e61454ab148a9f4063.png",
      "name" : "ショッツル鉱山"
    }...
  ]
}
5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?