我不知道如何解析下面代码中的内容。
有人可以帮忙吗?
func callService(usr: String, pwdCode: String) {
let url = NSURL(string: "http://inspect.dev.cbre.eu/SyncServices/api/jobmanagement/PlusContactAuthenticationPost")
var xmlParse:NSString = ""
var data : NSData!
let request = NSMutableURLRequest(URL: url!)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.HTTPMethod = "POST"
let dictionary = ["email": usr, "userPwd": pwdCode]
var error: NSError?
if let body = NSJSONSerialization.dataWithJSONObject(dictionary, options: nil, error: &error) {
request.HTTPBody = body
} else {
println("JSON error: \(error)")
}
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data, response, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
// xmlParse=NSString(data: data, encoding: NSUTF8StringEncoding)!
// let data = (xmlParse as NSString).dataUsingEncoding(NSUTF8StringEncoding)
// NSXMLParser(data : NSData)
// xmlParse=NSString(data: data, encoding: NSUTF8StringEncoding)!
// xmlParse=response
// println(xmlParse)
}
task.resume()
}
data
是否看起来像有效的 XML? - Rob