我正在为Instagram构建一个照片浏览器。我没有任何运行时错误或崩溃但显然我的getPath功能块中的逻辑需要工作,因为NSError说
json错误:错误Domain = NSCocoaErrorDomain Code = 3840" JSON文本没有以数组或对象开头,并且选项允许未设置片段。" UserInfo = {NSDebugDescription = JSON文本不以数组或对象开头,并且选项允许未设置片段。}
我已经检查了类似的SO问题,但它们更多是以json语法为中心和/或讨论我不知道它们如何应用于我的代码的数组对象。
我的捕获似乎没问题,但我需要数据采集方面的帮助。
func get(path: String) {
let url = NSURL(string: path)
lastSearchURL = path
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
print("Task completed")
if error != nil {
print(error!.localizedDescription)
}
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
//self.delegate?.didFailToGetMedia?(error!)
let results: NSArray = jsonResult["data"] as! NSArray
self.delegate?.didFetchMediaItems?(results)
} catch let error {
print("json error: \(error)")
}
})
task.resume()
}
答案 0 :(得分:0)
我发现它与我的API设置有关。本教程非常好。 https://auth0.com/docs/connections/social/instagram
def matcher(keywords, searcher):
for sentence in searcher:
sentence= set(sentence.split()) # split sentence into words
for key,words in keywords.iteritems():
if sentence & words: # if these two sets of words intersect, output the key
print key
keyword_dictionary = {
'Animals' : {'animal', 'dog', 'cat'},
'Art' : {'art', 'sculpture', 'fearns','graphic','display','lights'},
'Fruit' : {'yellow','fruit'},
}
matcher(keyword_dictionary, ["wendy bought a dog","that's a red fruit"])
# output: Animals
# Fruit
答案 1 :(得分:0)
实际上这是服务器端的问题。即,响应既不是数组也不是字典,
所以请让后端团队解决错误:)