In my API, I'm dealing with a JSON request parameter that includes an HTML string. This HTML string references CSS styles from a separate .css file. However, when an HTML element has two CSS classes assigned to it, neither of the classes' styles are being applied.
Below is the method I've created to generate the dictionary:
private func createCalendarInviteDictionary() -> [String: Any] {
var calendarInviteDict = [:] as [String: Any]
calendarInviteDict["emailId"] = hostDict["HostEmailAddress"]
calendarInviteDict["startTime"] = mgVisitorInfo.startDate
calendarInviteDict["endTime"] = mgVisitorInfo.endDate
calendarInviteDict["location"] = mgVisitorInfo.locationSite
calendarInviteDict["subject"] = "Welcome!!"
calendarInviteDict["allDayEvent"] = "no"
calendarInviteDict["isSkypeMeeting"] = "no"
calendarInviteDict["isHigh"] = "yes"
calendarInviteDict["requiredAttendees"] = [mgVisitorInfo.email]
calendarInviteDict["optionalAttendees"] = []
return calendarInviteDict
}
Next, here's an incomplete method where I call the previous one and convert the dictionary to JSON:
private func createCalendarInvite(_ completion: @escaping dataRequestCompletionBlock) {
var calendarInviteDict = createCalendarInviteDictionary() as [String: Any]
let emailContentHelper = EmailContentHelper()
calendarInviteDict["body"] = emailContentHelper.constructEmailBody()
var calendarInviteJSON = ""
if let theJSONData = try? JSONSerialization.data(
withJSONObject: calendarInviteDict,
options: [.prettyPrinted]) {
calendarInviteJSON = String(data: theJSONData, encoding: .utf8)!
print("JSON string = \(calendarInviteJSON)")
}
let calendarInviteParams = ["requestJSONString": calendarInviteJSON] as [String: String]
// do something else
}
This is what gets logged for the JSON String in the console:
... (omitted for brevity)
The issue arises when a HTML segment with 2 CSS classes is included in the JSON. While elements with only one class render correctly, those with multiple classes don't pick up any properties from either class.
I could resort to using inline styles, but due to the need for consistency across multiple instances within the HTML, I prefer utilizing the CSS classes defined in a separate .css file.
What changes should be implemented to ensure correct rendering of HTML segments with multiple CSS classes?