ios - iOS swift 中的错误域=NSCocoaErrorDomain 代码=3840?

标签 ios json swift

之前一切正常,但现在出现错误,例如

错误域 = NSCocoaErrorDomain 代码 = 3840 “JSON 文本未以数组或对象开头,并且未设置允许片段的选项。” UserInfo={NSDebugDescription=JSON 文本未以数组或对象开头,并且未设置允许片段的选项。}

我的JSON解析代码就像

 func JSONParseArray(jsonString: String) -> [AnyObject] {
            if let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
                if let array = (try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)))  as? [AnyObject] {
                    return array
                }
            }
            print(strings)
            return [AnyObject]()
        }

可能会出现什么问题?或者我做错了什么?

我的 JSOn 字符串值为

http://test.domain.in/transfer/jsp/wsCall.jsp?dataFormat=JSON&requestData= {“requestId”:“1447417335364”,“requestType”:“登录”,“channelId”:“移动”,“clientId”:“RG”,“groupId”:“测试”,“loginId”:“test@test. com","密码":"cFzc3dvcmRAMA==","noofAttempts":"1","ipAddress":"8ADCD445-A4F6-49EA-A344-35313A0AD","key":"MzQM3OTA4NDgxMjY4bWlsbGVy"}

最佳答案

request.setValue("text/json", forKey: "Content-Type")

关于ios - iOS swift 中的错误域=NSCocoaErrorDomain 代码=3840?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888047/

相关文章:

java - Android 数组的空指针

java - 使用jackson解析时如何防止多余的字符串转换步骤?

arrays - Swift 巨大的数组字典,非常慢

ios - fatal error : Index out of range, 由于反复按赞和心形按钮

iphone - 如何更改布局 View Controller ?

objective-c - UIButton 在隐藏时不起作用

ios - 当任何其他 UIViewController 被插入堆栈时如何从 UITabBarController 隐藏 TabBar

ios - 获取用户在 iOS 上下载的应用列表

Javascript | JSON 和数组

ios - iOS 10 中的 UILabel,制作文本字体