Swift将http响应转换为数据字典

时间:2017-05-06 04:17:54

标签: swift enums nsdictionary icalendar

我是Swift,iOS开发的新手。

HTTP请求:

request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data, error == nil else {                                                 // check for fundamental networking error
        print("error=\(error)")
        return
    }

    if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {           // check for http errors
        print("statusCode should be 200, but is \(httpStatus.statusCode)")
        print("response = \(response)")
    }

 let responseString = String(data: data, encoding: .utf8)
    print("responseString = \(responseString)")
}
task.resume()

响应字符串看起来像这样

BEGIN:VCALENDAR
PRODID:-//MobileUGStdTT//iCal4j 1.0//EN //DateGenerated 06 May 2017 12:05
 :07
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20170506T040507Z
DTSTART:20170109T090000
DTEND:20170109T120000
SUMMARY:SG4207 (L)
DESCRIPTION:SG4207-MOBILE WIRELESS SOLUTION DESIGN (LECTURE)
LOCATION:ISS-03-03
UID:20170506T040507Z-MobUGStdTT@fe80:0:0:0:250:56ff:fea6:c7e%3
TZID:Asia/Singapore
BEGIN:VALARM
TRIGGER:-PT15M
REPEAT:4
DURATION:PT5M
ACTION:DISPLAY
DESCRIPTION:SG4207-MOBILE WIRELESS SOLUTION DESIGN (LECTURE) @ ISS-03-03\
 , starts 0900
END:VALARM
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20170506T040507Z
DTSTART:20170116T090000
DTEND:20170116T120000

我需要将此回复转换为NSDataDictionary / ENUM,因为它不是常规JSON我发现很难将其转换为。{/ p>

这些是密钥 - DTSTART,摘要,描述我需要。

感谢您的帮助。

0 个答案:

没有答案