【发布时间】:2016-02-26 13:30:48
【问题描述】:
之前一切正常,但现在出现类似
的错误错误域=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":"LOGIN","channelId":"MOBILE","clientId":"RG","groupId":"Test","loginId" :"test@test.com","password":"cFzc3dvcmRAMA==","noofAttempts":"1","ipAddress":"8ADCD445-A4F6-49EA-A344-35313A0AD","key":"MzQM3OTA4NDgxMjY4bWlsbGVy" }
【问题讨论】:
-
jsonString 的值是多少?
-
@Midhun 我更新了我的问题
-
您的 jsonstring 无效。这部分
http://test.domain.in/transfer/jsp/wsCall.jsp?dataFormat=JSON&requestData=导致问题。 -
@Midhun 我的字符串有什么问题?可以请解释一下,以便我可以处理它..因为它之前工作正常
-
http://test.domain.in/transfer/jsp/wsCall.jsp?dataFormat=JSON&requestData=不应成为您的 jsonString 的一部分。你必须弄清楚它为什么会来。