tristanhimmelman/AlamofireObjectMapper

How can i print JSON

Closed this issue · 2 comments

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.

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

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.