Попробуйте этот код,
Добавить это расширение
extension Array where Element: Codable {
public var toData: Data {
let encoder = JSONEncoder()
do {
return try encoder.encode(self)
}
catch {
fatalError(error.localizedDescription)
}
}
public var toJson: String? {
return toData.toJson
}
}
extension Data {
// Convert NSData to String
public var toJson : String? {
return String(data: self, encoding: String.Encoding.utf8)
}
}
Ваш веб-API Parameters
, как
let parameters: [String : Any] = [
"paymenttype":"debitcard",
"coupon":"",
"products":[["pid":"72","qnty":"1"],["pid":"4","qnty":"1"],["pid":"3","qnty":"1"]].toJson ?? "[]",
"grandtotal":"71499.52",
"discount":"",
"itemtotalval":"69417.0",
"cgst":"1041.26",
"comment":"sss",
"sgst":"1041.26",
"billingaddress":[["bfname":"debdeep nandy","bmobilenumber":"9875463215","bpincode":"823691" , "baddress":"kolkata","bcity":"kolkata","bstate":"West Bengal","bcountry":"india","bemail":"dev@gmail.com"]].toJson ?? "[]",
"shippingaddress":[["sfname":"debdeep nandy","smobilenumber":"9875463215","spincode":"823691","saddress":"kolkata","scity":"kolkata","sstate":"West Bengal","scountry":"india","semail":"india"]].toJson ?? "[]",
"user_id":1
]
А твоя другая часть
else {
print("Malformed data received from fetchAllRooms service")
debugPrint(String(data: response.data!, encoding: String.Encoding.utf8))
//Print out our data
return
}
Примечание: в Alamofire
параметр Передайте значение Array
или Dictionary
, используя формат строки JSON, тогда это сработает.