1

i want to sending multipart array of string.

ex)

let list = ["ffff","bbbb","cccc"] 
let params = [
    "a" : "a",
    "b" : "b",
    "list : list
]

a and b case

for (key, value) in params {
    multipartFormData.append( value.data(using: String.Encoding.utf8)! , withName: key)    
}

but how to list send?

plz help me.

1
  • Hi, so which way in the answer did you choose to solve your issue. I have the same issue, but if we use the first way, I don't know which field should we put the json of all params Commented Feb 7, 2018 at 15:17

1 Answer 1

2

Now you have two ways to do it:

1: Make whole params as a JSON

2: Make only the array as an encoded JSON string.

In your case you can use 1:

let list = ["ffff","bbbb","cccc"] 

let data = try! JSONSerialization.data(withJSONObject: list, options: .prettyPrinted)

let jsonString = String(data: data, encoding: .utf8)!

let params = [
    "a" : "a",
    "b" : "b",
    "list : jsonString
]
Sign up to request clarification or add additional context in comments.

5 Comments

thank you for help me! : ) but If I send ["aaa", "BBB"], the server will send '[\ n "aaa", \ n "BBB" \ n]' I get the value this way. Why?
So basically server need to handle it by the stripes method in laravel php.
umm... is it impossible then to send ["aaa", "BBB"]?
You can't pass array directly.
OK Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.