此代码用于在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")
}
})
}
答案 0 :(得分:3)
尝试向NSDictionary
投射。它应该可以解决你的问题。
self.array = NSJSONSerialization.JSONObjectWithData(
responseData,
options: NSJSONReadingOptions.MutableLeaves, error: &err
) as! NSDictionary
也许这是来自Twitter的正确回报。