I want convert array of dictionaries to a json string so i have used
func json(from object: NSMutableArray) -> String? {
guard let data = try? JSONSerialization.data(withJSONObject: object) else {
return nil
}
return String(data: data, encoding: String.Encoding.utf8)
}
and it is returning a json string but with an optional before the stirng
finalString = json(from: saveArray)
print(finalString)
Optional("[{\"CreatedOn\":\"Thursday, Mar 29, 2018\",\"DayName\":\"Wed\",\"EmployeeID\":\"1\",\"AppointmentType\":\"3\",\"FromTime\":\"09:00:00\",\"AppointmentDate\":\"Wednesday, May 16, 2018\",\"ToTime\":\"10:00:00\",\"CreatedBy\":\"40289\",\"PatientID\":\"17586\",\"ResourceID\":\"1\",\"PatientConditionId\":\"17590\"},{\"CreatedOn\":\"Thursday, Mar 29, 2018\",\"DayName\":\"Thu\",\"EmployeeID\":\"1\",\"AppointmentType\":\"3\",\"FromTime\":\"09:00:00\",\"AppointmentDate\":\"Thursday, May 17, 2018\",\"ToTime\":\"10:00:00\",\"CreatedBy\":\"40289\",\"PatientID\":\"17586\",\"ResourceID\":\"1\",\"PatientConditionId\":\"17590\"},{\"CreatedOn\":\"Thursday, Mar 29, 2018\",\"DayName\":\"Fri\",\"EmployeeID\":\"1\",\"AppointmentType\":\"3\",\"FromTime\":\"09:00:00\",\"AppointmentDate\":\"Friday, May 18, 2018\",\"ToTime\":\"10:00:00\",\"CreatedBy\":\"40289\",\"PatientID\":\"17586\",\"ResourceID\":\"1\",\"PatientConditionId\":\"17590\"}]")
and when i unwrap this value...
finalString = json(from: saveArray)
print(finalString!)
then I get...
[
{
"CreatedOn": "Thursday, Mar 29, 2018",
"DayName": "Wed",
"EmployeeID": "1",
"AppointmentType": "3",
"FromTime": "09:00:00",
"AppointmentDate": "Wednesday, May 16, 2018",
"ToTime": "10:00:00",
"CreatedBy": "40289",
"PatientID": "17586",
"ResourceID": "1",
"PatientConditionId": "17590"
},
{
"CreatedOn": "Thursday, Mar 29, 2018",
"DayName": "Thu",
"EmployeeID": "1",
"AppointmentType": "3",
"FromTime": "09:00:00",
"AppointmentDate": "Thursday, May 17, 2018",
"ToTime": "10:00:00",
"CreatedBy": "40289",
"PatientID": "17586",
"ResourceID": "1",
"PatientConditionId": "17590"
},
{
"CreatedOn": "Thursday, Mar 29, 2018",
"DayName": "Fri",
"EmployeeID": "1",
"AppointmentType": "3",
"FromTime": "09:00:00",
"AppointmentDate": "Friday, May 18, 2018",
"ToTime": "10:00:00",
"CreatedBy": "40289",
"PatientID": "17586",
"ResourceID": "1",
"PatientConditionId": "17590"
}
]
just an array structure.
now how can i achieve the json string structure without the optional value?????