I want to send a json object through Post method in this following format
[
{
"product_id": 8,
"quantity": 2
},
{
"product_id": 19,
"quantity": 1,
"variations": {
"pa_size": "XL"
}
}
]
and store this JSON in sql database
in following format
here is my code:
//i get the products id and quantity
for var i=0; i<ct ; i++ {
let paramsArray = [["product_id": (prId[i]), "quantity" : (productQty["\(prId[i])"]!)]]
//converting array to json using SwiftyJSON
let paramsJSON = JSON(paramsArray)
let paramsString = paramsJSON.rawString(NSUTF8StringEncoding, options: [])
//appending products to array
cartProducts.append(paramsString!)
}
//printing array products
print("cartPro:\(cartProducts)")
printed output of array comes like this i also tried to remove backslash
cartPro:["[{\"product_id\":19,\"quantity\":1}]", "[{\"product_id\":8,\"quantity\":1}]"]
i want out put like this so i can send through post method using api:
[{"product_id":19,"quantity":1}, {"product_id":8,"quantity":1}]
is there any other way i can append JSON objects to array and send? or i'm doing it wrong?
please help me