Hello i am encoding
array to json
so that i have created model class like below
class QuotationListDataModel: Codable{
var quatation_id: String?
var PartNumber: String?
var Description: String?
var Quantity: String?
var AvailableStockQty: String?
var Each: String?
init(quatation_id: String?, PartNumber: String?,Description: String?,Quantity:String?,AvailableStockQty: String?,Each: String?) {
self.quatation_id = quatation_id
self.PartNumber = PartNumber
self.Description = Description
self.Quantity = Quantity
self.AvailableStockQty = AvailableStockQty
self.Each = Each
}
}
And the i am encoding like below
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let jsonData = try encoder.encode(quotationSeelctedData)
if let jsonString = String.init(data: jsonData, encoding: .utf8) {
print(jsonString)
}
} catch {
print("the encoding failed")
}
and with this code json encoded successfully but order not maintained when i print encoded string then i get output like below
[
{
"quatation_id": "67",
"Description": "PSH BTN",
"Each": "140.00 Total 40320.00",
"PartNumber": "15",
"Quantity": "288",
"AvailableStockQty": "0"
},
{
"quatation_id": "66",
"Description": "SELF-CLOSING 4-ARM HANDLE (PLATED BRASS)",
"Each": "14.00 Total 3612.00",
"PartNumber": "000015-40",
"Quantity": "258",
"AvailableStockQty": "10"
}
]
And i want output something like below
Part Number : 000015-40
Description : SELF-CLOSING 4-ARM HANDLE (PLATED BRASS)
Quantity : 10
Available Stock Qty. : 10
Each: 12.1 Total: 121
can any one tell me how to maintain order as per my model class has