Json添加了反斜杠Swift

时间:2016-08-01 12:14:47

标签: ios json swift swift2

当我从Web服务JSON获得结果时,就像这样:

responseString = "\{\\\"code\\\":\\\"OK\\\",\\\"description\\\":\\\" DOĞRULAMA KODUNUZ 6806\\\"}\"

但是当我打印它时。

let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
            print("responseString = \(responseString)")

我看到了这个回应:

responseString = Optional("{\"code\":\"OK\",\"description\":\"DOĞRULAMA KODUNUZ 6806\"}")

我想解析它。但我得到格式错误。我的代码如下:

let responseJson = JSONStringify(responseString!)
let json: AnyObject? = responseJson.parseJSONString

let code = (json as! NSDictionary)["code"] as! String

let description = (json as! NSDictionary)["description"] as! String 
print("code: \(code)")
print("description: \(description)")

感谢您的帮助。

0 个答案:

没有答案