0

I would construct the below payload dynamically for a POST service call. I am not sure how to create a list of strings in dictionary

{
    "Id":"2025",
    "deviceType": "iphone",
    "category": ["Dental", "Vision"] 
}

My code

var categoryList = ["Dental", "Vision"]
let json = ["Id": "2025", "deviceType": "iphone", "category": categoryList] as! Dictionary<String, String>     
let jsonData = try? JSONSerialization.data(withJSONObject: json)
Matias Jurfest
  • 1,378
  • 16
  • 25
Warrior
  • 39,156
  • 44
  • 139
  • 214

1 Answers1

1

you can do like this:-

and no need to onvert json into data you can directly post this json in SERVICE CAll as a parameter

let jsonToSend:[String:Any] = [
    "Id":"pass your id here",
    "deviceType":"device type here",
    "category":"category array here"
]
Irshad Ahmad
  • 1,363
  • 11
  • 17