我想将字典转换为json,字典如下:
[
[
"user_event" : "Optional({\n \"strokes\" : {\n \"oldText\" : \"er\",\n \"selection\" : \"error\",\n \"candidates\" : \"error|errors|era\",\n \"context\" : \"error \"\n }\n})",
"device_type" : "x86_64",
"language" : "EN_US"
],
[
"user_event" : "Optional({\n \"strokes\" : {\n \"oldText\" : \"\",\n \"selection\" : \"messages\",\n \"candidates\" : \"messages|message|in\",\n \"context\" : \"error messages \"\n }\n})",
"device_type" : "x86_64",
"language" : "EN_US"
]
]
我使用以下代码:
let data = try NSJSONSerialization.dataWithJSONObject(object, options: NSJSONWritingOptions())
let json = NSString.init(data: data, encoding: NSUTF8StringEncoding)
但结果字符串的字符为"可选("这将导致json解码器进程失败,如何排除这些附加字符?