gpt4 book ai didi

ios - 推特搜索 API 1.1 错误 : Could not cast value of type '__NSCFDictionary' to 'NSArray'

转载 作者:可可西里 更新时间:2023-11-01 01:04:39 25 4
gpt4 key购买 nike

此代码用于在 Twitter 上搜索主题标签,但给出错误提示无法将“__NSCFDictionary”类型的值转换为“NSArray”

当我使用以下 URL 访问我的主页时间线时,相同的代码工作正常 https://api.twitter.com/1.1/statuses/home_timeline.json

func getTimeLine() {

let accountType = account.accountTypeWithAccountTypeIdentifier(
ACAccountTypeIdentifierTwitter)

self.account.requestAccessToAccountsWithType(accountType, options: nil,
completion: {(success: Bool, error: NSError!) -> Void in

if success {
let arrayOfAccounts =
self.account.accountsWithAccountType(accountType)

if arrayOfAccounts.count > 0 {

let twitterAccount = arrayOfAccounts.last as! ACAccount

let requestURL = NSURL(string:
"https://api.twitter.com/1.1/search/tweets.json?q=%23baseball&result_type=recent%3F")
let parameters = ["count" : "10"]

let postRequest = SLRequest(forServiceType:
SLServiceTypeTwitter,
requestMethod: SLRequestMethod.GET,
URL: requestURL,
parameters: nil)

postRequest.account = twitterAccount

postRequest.performRequestWithHandler(
{(responseData: NSData!, urlResponse: NSHTTPURLResponse!, error: NSError!) -> Void in
var err: NSError?
self.array = NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.MutableLeaves, error: &err) as! [AnyObject**strong text**]
if self.array.count != 0 {
dispatch_async(dispatch_get_main_queue()) {
self.mycollectionView.reloadData()
}
}
})
}
}
else {
println("Failed to access account")
}
})
}

最佳答案

尝试转换为 NSDictionary。它应该可以解决您的问题。

self.array = NSJSONSerialization.JSONObjectWithData(
responseData,
options: NSJSONReadingOptions.MutableLeaves, error: &err
) as! NSDictionary

也许这是来自 Twitter 的正确返回。

关于ios - 推特搜索 API 1.1 错误 : Could not cast value of type '__NSCFDictionary' to 'NSArray' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com