tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

How can i print JSON #186

Closed santhoshs5 closed 7 years ago

santhoshs5 commented 7 years ago

I am using following method to parse the response. Alamofire.request(self.router).responseObject{ (response: DataResponse) in

I am getting data which custom model object.

haraldmartin commented 7 years ago

You can chain response handlers like this:

Alamofire.request(self.router)
  .responseJSON { (response) in
    print("json")
    print(response.result.value ?? "no json")
  }
  .responseObject { (response: DataResponse) in
    …
  }

See more https://github.com/Alamofire/Alamofire#chained-response-handlers

yangjehpark commented 7 years ago

And also, if you are handling the 'Mappable' model object, you can print like this.

func logJSON(mappable: Mappable) {
    print("\(mappable.toJSON())")
}

toJSON() is a 'Mappable' object's extension function.