title: How to create struct and init values from GET url in swift
body: <p>my JSON :</p>
  
  <pre><code>   {
    "id": "70",
    "bname": "Municipal Corporation - Water",
    "bcategoryname": "Water",
    "bcustomerparms": "[{\"paramName\":\"Consumer Number\",\"dataType\":\"NUMERIC\",\"optional\":\"false\",\"minLength\":\"1\",\"maxLength\":\"10\" .      },
             {\"paramName\":\"Mobile Number\",\"dataType\":\"NUMERIC\",\"optional\":\"false\",\"minLength\":\"10\",\"maxLength\":\"10\"},
             {\"paramName\":\"Email . Id\",\"dataType\":\"ALPHANUMERIC\",\"optional\":\"false\",\"minLength\":\"5\",\"maxLength\":\"100\"}]",
   }
    {    
   "id": "68",
   "bname": "Municipal Corporation - 12",
   "bcategoryname": "Water",
   "bcustomerparms": "[{\"paramName\":\"K No\",\"dataType\":\"ALPHANUMERIC\",\"optional\":\"false\",\"minLength\":\"7\",\"maxLength\":\"20\"}]",
   } 
  </code></pre>
  
  <p>I am unable to create struct from get api, i need bname and its paramNamew according to its bcategoryname, i need to disply bname in table and if i select i need its all paramNames.</p>
  
  <p>Here is code:</p>
  
  <pre><code>struct JsonDataBiller{
  var bname: String?
  var bcategoryname: String?
  var bcustomerparms: [cDetails]
  
  init(bname: String, bcategoryname: String, bcustomerparms: [cDetails]){
  
      self.bname = bname
      self.bcategoryname = bcategoryname
      self.bcustomerparms = bcustomerparms
  }
  }
  
  struct cDetails{
  var paramName: String?
  var minLength: String?
  var maxLength: String?
  
  init(paramName: String, minLength: String, maxLength: String)
  {
      self.paramName = paramName
      self.minLength = minLength
      self.maxLength = maxLength
  }
  }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>class AllMakePaymentViewController: UIViewController {
  
  @IBOutlet weak var tableView: UITableView!
  
  var jsonData = [JsonDataBiller]()
  
  var minLength: String?
  var maxLength: String?
  var bName: String?
  var category: Category?
  var categoryName: String?
  var paramName: String?
  
  var ParamArray = [String]()
  
  var labelText: String?
  override func viewDidLoad() {
      super.viewDidLoad()
  
      allPaymentService()
  }
  
  func allPaymentService(){
  
      let urlStr = "https://dev.anyemi.com/webservices/anyemi/api.php?rquest=billermdm"
      let url = URL(string: urlStr)
      URLSession.shared.dataTask(with: url!, completionHandler: {(data, response, error) in
          guard let respData = data else {
              return
          }
          guard error == nil else {
              print("error")
              return
          }
          do{
              let jsonObj = try JSONSerialization.jsonObject(with: respData, options: .allowFragments) as! [String: Any]
              //print("the all make payment json is \(jsonObj)")
              let billerdetailsArray = jsonObj["billerdetails"] as! [[String: Any]]
  
              for billerdetail in billerdetailsArray {
  
                  self.categoryName = billerdetail["bcategoryname"] as? String
  
                  let customrParams = billerdetail["bcustomerparms"] as! String
                  let res = try JSONSerialization.jsonObject(with:Data(customrParams.utf8)) as! [[String: Any]]
  
                  for item in res {
  
                      self.paramName = item["paramName"] as? String
  
                      self.minLength = item["minLength"] as? String
                      self.maxLength = item["maxLength"] as? String
                                              if self.categoryName == "Water"{
                          let bName = billerdetail["bname"] as? String
                          self.jsonData.append(JsonDataBiller(bname: bName ?? "", bcategoryname: self.categoryName ?? "", bcustomerparms: [paramName: paramName, minLength: minLength, maxLength: maxLength]))
  
                      }
                      if self.categoryName == "Electricity"{
                          let bName = billerdetail["bname"] as? String
                          self.jsonData.append(JsonDataBiller(bname: bName ?? "", bcategoryname: self.categoryName ?? "", bcustomerparms: [paramName: paramName, minLength: minLength, maxLength: maxLength]))
                      }
                  }
              }
              DispatchQueue.main.async {
                  self.tableView.reloadData()
              }
          }catch {
              print("catch error")
          } }).resume()
  }
  }
  </code></pre>
  
  <p>error:</p>
  
  <blockquote>
    <p>Contextual type '[cDetails]' cannot be used with dictionary literal</p>
  </blockquote>
  
  <p>Here i need to add <code>bnam</code> according to its <code>bcategoryname</code> and <code>paramName</code> according to <code>bname</code></p>
  
  <p>please help me in the above code please, i am unable to solve this issue, i got stuck from long time.</p>