title: how to fetch data from JSON into UIPickerView using swift 3
body: <p>I am trying to fetch data from JSON into UIPickerview but i don't the format for parsing that data and fetch it from picker.</p>
  
  <p><a href="https://i.stack.imgur.com/6twRc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6twRc.png" alt="enter image description here"></a></p>
  
  <p>I need to get name and code from parsed data in my pickerview when i tap the textfield
  <strong>Parsed code</strong></p>
  
  <pre><code>    let url = URL(string: "http://api.railwayapi.com/v2/name-to-code/name/\. (pickTxtField.text!)/apikey/fe22em16kb")! //change the url
      let session = URLSession.shared
      let request = URLRequest(url: url)
      let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error in
          guard error == nil else { return
          }
          guard let data = data else { return
          }
          do {
              if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
               {
                  DispatchQueue.main.async
                      {
                          var display = String(describing: json["stations"]!)
                          let realname = json["code"]
                          let departmentName = json["name"]
                          self.department.append(departmentName! as! String)
                          self.pickView.reloadAllComponents() // this is reference to your pickerView. Make it global and use it
                  }
              }
          }catch let error {
              print(error.localizedDescription) }
      })
      task.resume()
  </code></pre>