title: How to get data from nested JSON using JSONDecoder in swift 4?
body: <p>I am very new in swift, first of all I want to know what is the major difference between Encoding and Decoding. Secondly, I am try to get a particular value from the response as shown below:</p>
  
  <p><a href="https://i.stack.imgur.com/NqS9h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NqS9h.png" alt="enter image description here"></a> </p>
  
  <p>I want to decode the value of gender_category and put it in piker, here is what i have done till now:</p>
  
  <pre><code>struct Gender: Decodable {
  
  let result : [Result]
  
  enum CodingKeys :String, CodingKey {
      case result
  }
  
  struct Result: Decodable {
      let genderCategory: String
  
  
      enum CodingKeys : String, CodingKey {
  
          case genderCategory = "gender_category"
      }
  }
  }
  </code></pre>
  
  <p>And my code to get response is this:</p>
  
  <pre><code> func getGenderValueFromJSON()  {
      let url = URL(string: "http://www.----------.com/GenderList/get")
      URLSession.shared.dataTask(with: url!) { (data, response, error) in
          if error == nil{
              do{
  
                  let result  = try JSONDecoder().decode(Gender.self, from: data!)
                  print(result)
              }catch let error as NSError{
  
                  print("Parse Error\(error)")
              }
          }
  
          }.resume()
  }
  </code></pre>
  
  <p>I get my result in this way:</p>
  
  <p>Gender(result: [something.Gender.Result(genderCategory: "Male"), something.Gender.Result(genderCategory: "Female"), something.Gender.Result(genderCategory: "Transgender"), something.Gender.Result(genderCategory: "Others")])</p>
  
  <p>But how do I get only the value of genderCategory?</p>