-4

I have a problem I want to handle a JSON Response with Alamofire in Swift So I found this answer on Stackoverflow unfortunately this post is a few days older. My question is how can I receive the data from Alamofire on first button press (without swiftyJSON). I hope someone could help me.

This is the link I found on Stackoverflow.

Handle JSON Response with Alamofire in Swift

Community
  • 1
  • 1
user2492972
  • 1
  • 1
  • 1

1 Answers1

3

this is a small example.

This is what the JSON returns if it fails json_file.json

{ "transaction":"error" }

This is what the JSON returns if its success json_file.json

{ "transaction":"success" }

this is the code , you must add your own URL that will return any of those json responses. (example only)

        Alamofire.request(.GET, "http://myjsonexamplewebsite.com/json_file.json", parameters:nil)

            .responseJSON { (_, _, JSON, _) in

                //println(JSON)
                var response = JSON as NSDictionary

                var transaction = response.objectForKey("transaction") as String

                if transaction == "success" {

                    NSLog("JSON response was successfull")

                }
                else {

                    NSLog("JSON response had an Error")
                }

        }
Eddwin Paz
  • 2,842
  • 4
  • 28
  • 48