Joyal Clifford
Joyal Clifford

Reputation: 1212

How to use Alamofire with JSONDecoder?

I am try to parsing google Direction API as below. https://developers.google.com/maps/documentation/directions/start

but unable to get any result from JSONDecoder , it always return Error block I am using Alamofire code as below for parsing .

 let decoder = JSONDecoder()
                        do {
                            let userDictionary    =  try   decoder.decode(DirectionParser.self, from: response.data!)
                        print("The Parser \(userDictionary)")

                        } catch {
                            print("Error")
                        }

Upvotes: 1

Views: 365

Answers (1)

sawin0
sawin0

Reputation: 663

I think you are doing right. Just make sure you are trying to parse what you want. You can do this by printing out

print(response.anythingYouWant)

Can you show us DirectionParser. Make sure it is like below code

struct DirectionParse: Decodable {
   //things you want to fetch
}

P.S I would have commented if I had reputation 50+.

Upvotes: 2

Related Questions