swift - Sending struct through POST to php
one text
I have an iOS app that is written in Swift.
The app has a cart, with items of a struct called Order
, which has a productName
inside it.
When the order is finished, I am sending the data to a php file, so I can upload the data to my database.
The problem is, when I send the variable order
containing the users wishes products with the Order
struct, and then I get the variable on the PHP page like so:
$order = $_POST["order"];
When I echo $order;
this is the response I get in the console of Xcode:
responseString = Optional("[MyAppName.Order]")
This is my Order struct:
struct Order: Codable {
let productName: String
let productQuantity: Int
let productPrice: Int
init(productName: String, productQuantity: Int, productPrice: Int) {
self.productName = productName
self.productQuantity = productQuantity
self.productPrice = productPrice
}
}
I guess I need to change the struct so it can be read in a PHP file. What can I do to change the data in the struct so it will be readable for a PHP file?
Source