title: Swift multipart/form-data upload with append String Array to body (Issue: Array goes as String to Server)
body: <p>Im trying to send an String Array to the server in a multipart request using Alamofire Swift library, i tried several ways to encode the array but most of the time it goes as a string. can anyone help me with this. except the array sending image uploading and other values goes fine to the server. below is my code.</p>
  
  <pre><code>var parameters: Parameters = [
          "UEmail": userObj.email,
          "UFirstName": fName,
          "ULastName": lName,
          "VisitedCountries": getVisitedCountryCodeList() //return String array
      ]
  
  let headers: HTTPHeaders
      headers = ["Content-type": "multipart/form-data"]
  
      AF.upload(multipartFormData: { (multipartFormData) in
          for (key, value) in parameters {
              if let subArray = value as? NSArray {
                  do {
                      if(key == "VisitedCountries"){
                          let data = try JSONSerialization.data(withJSONObject: self.getVisitedCountryCodeList(), options: [])
                          multipartFormData.append(data, withName: "VisitedCountries" )
                      }
                  } catch {
                      print("error msg")
                  }
              } else {
                  multipartFormData.append((value as! NSString).data(using: String.Encoding.utf8.rawValue)!, withName: key )
              }
          }
  
          if(self.selectedProfileImage != nil){
              guard let imgData = self.selectedProfileImage.jpegData(compressionQuality: 2) else { return }
              multipartFormData.append(imgData, withName: "file", fileName: "image.jpeg", mimeType: "image/jpeg")
          }
  
      },usingThreshold: UInt64.init(),
        to: "\(Constants.SERVER_URL)\(Constants.USER_EDIT)",
        method: .post,
        headers: headers).response{ response in
          SVProgressHUD.dismiss()
          if(response.data != nil) {
  
              do {
                  if let jsonData = response.data {
                      let parsedData = try JSONSerialization.jsonObject(with: jsonData) as! Dictionary&lt;String, AnyObject&gt;
  
                      print(parsedData)
                  }
  
              } catch {
                  print("error msg")
              }
          } else {
              print("user edit response2 \(response) end")
          }
      }
  </code></pre>
  
  <p>above is my AF.upload code. array append is the section i have the issue.
  here is the array appending code.</p>
  
  <pre><code>//getVisitedCountryCodeList() returns string array  
  
  let data = try JSONSerialization.data(withJSONObject: self.getVisitedCountryCodeList(), options: []) 
  multipartFormData.append(data, withName: "VisitedCountries" )
  </code></pre>
  
  <p>i tried below code as well</p>
  
  <pre><code>multipartFormData.append(try JSONEncoder().encode(self.getVisitedCountryCodeList()), withName: key )
  </code></pre>
  
  <p>the below is what server gets, which is string not array</p>
  
  <pre><code>"VisitedCountries"=&gt;"[\"ALG\",\"ARG\"]"
  </code></pre>
  
  <p>but i need to send like this</p>
  
  <pre><code>"VisitedCountries"=&gt; ["ALG","ARG"]
  </code></pre>