We are having array of json objects like below:
[{
"CompanyCode": "1",
"MachineCode": null,
"MachineName": null,
"NoOfMeters": null,
"ScheduleNo": "12028",
"ScheduleDate": "17/2/2018 12:00:00 AM",
"ScheduleUser": "sales",
"CustomerCode": "0022100007",
"DeliveryCode": "0",
"SortOrder": "1",
"JobRefNo": "",
"CustomerName": "COLD STORAGE SUPERMARKETS ",
"CustAddress1": "GIANT COMPLEX",
"OutletName": "",
"OutAddress1": "",
"IsJobClosed": ""
}, {
"CompanyCode": "1",
"MachineCode": null,
"MachineName": null,
"NoOfMeters": null,
"ScheduleNo": "12029",
"ScheduleDate": "17/2/2018 12:00:00 AM",
"ScheduleUser": "sales",
"CustomerCode": "0022100008",
"DeliveryCode": "0",
"SortOrder": "1",
"JobRefNo": "",
"CustomerName": "COLD STORAGE WH - 21 TAMPINES ",
"CustAddress1": "GIANT COMPLEX",
"OutletName": "",
"OutAddress1": "",
"IsJobClosed": ""
}, {
"CompanyCode": "1",
"MachineCode": null,
"MachineName": null,
"NoOfMeters": null,
"ScheduleNo": "12027",
"ScheduleDate": "17/2/2018 12:00:00 AM",
"ScheduleUser": "winapp",
"CustomerCode": "0022100003",
"DeliveryCode": "0",
"SortOrder": "1",
"JobRefNo": "",
"CustomerName": "AVENZA PTE LTD ",
"CustAddress1": "83 CLEMENCEAU AVE",
"OutletName": "",
"OutAddress1": "",
"IsJobClosed": ""
}, {
"CompanyCode": "1",
"MachineCode": null,
"MachineName": null,
"NoOfMeters": null,
"ScheduleNo": "12025",
"ScheduleDate": "17/2/2018 12:00:00 AM",
"ScheduleUser": "winapp",
"CustomerCode": "0022100001",
"DeliveryCode": "0",
"SortOrder": "1",
"JobRefNo": "",
"CustomerName": "CASH ON DELIVERY (TO) ",
"CustAddress1": "CASH ON DELIVERY",
"OutletName": "",
"OutAddress1": "",
"IsJobClosed": ""
}, {
"CompanyCode": "1",
"MachineCode": null,
"MachineName": null,
"NoOfMeters": null,
"ScheduleNo": "12026",
"ScheduleDate": "17/2/2018 12:00:00 AM",
"ScheduleUser": "winapp",
"CustomerCode": "0022100002",
"DeliveryCode": "0",
"SortOrder": "1",
"JobRefNo": "",
"CustomerName": "DESPATCH - MT ",
"CustAddress1": "DESPATCH",
"OutletName": "",
"OutAddress1": "",
"IsJobClosed": ""
}]
We wanted group this array based on ScheduleUser key like section.
[
"Sales":[
{
}
{
}
]
"winapp":[
{
}
{
}
{
}
]
]
We have studied about grouping in swift 4 Here
But they given with array of string, we don't have idea to working json values. Kindly give us solution if any other way. we have referred following Link
We are not able to understand this.
Getting values from local
if let path = Bundle.main.path(forResource: "salesorder", ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
do{
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
let jsonDictionary = json as? [[String:Any]]
print(jsonDictionary!)
}catch let error{
print(error.localizedDescription)
}
} catch let error {
print(error.localizedDescription)
}
} else {
print("Invalid filename/path.")
}
Thanks in advance..