小编aot*_*n16的帖子

NSJSONSerialization错误.Code = 3840"字符0周围的值无效

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

8
推荐指数
1
解决办法
2万
查看次数

UITextInputMode.activeInputModes()在Swift 2中崩溃

我想在Swift 2中获得UITextInputMode但UITextInputMode.activeInputModes()崩溃了.

    let x = UITextInputMode.activeInputModes() // crash here

    for t in x {
        print(t)
    }
Run Code Online (Sandbox Code Playgroud)

ios uitextinput swift swift2

4
推荐指数
2
解决办法
739
查看次数

标签 统计

swift ×2

ios ×1

swift2 ×1

uitextinput ×1