NSJSONSerialization.JSONObjectWithData 使用像"abc"这样的字符串时出错,但使用"123"成功
我不知道为什么.
错误日志
2015-11-04 17:42:02.997 SwiftJsonDemo[27196:2701028] Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}
Run Code Online (Sandbox Code Playgroud)
码
//var str = "123" // ok
var str = "abc" // error
let strData = str.dataUsingEncoding(NSUTF8StringEncoding)
if let d = strData {
let urlStr = String(data: d, encoding: NSUTF8StringEncoding)
do {
let json = try NSJSONSerialization.JSONObjectWithData(d, options: NSJSONReadingOptions.AllowFragments)
} catch let e {
print(e)
}
} else {
print("data error")
}
Run Code Online (Sandbox Code Playgroud) 我想在Swift 2中获得UITextInputMode但UITextInputMode.activeInputModes()崩溃了.
let x = UITextInputMode.activeInputModes() // crash here
for t in x {
print(t)
}
Run Code Online (Sandbox Code Playgroud)