我的应用程序应该去特定的位置来下载它需要加载的网站.在2.3它的工作就像一个魅力,但因为我已经更新了xcode(我没有很多经验)它给我错误"类型'任何'没有下标成员"并突出显示"json"就在第三行之前
...Retriever = json["WEB"]...
Run Code Online (Sandbox Code Playgroud)
这是与之相关的代码.
let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments)
if let Retriever = json["WEB"] as? [[String: AnyObject]] {
for website in Retriever {
if let name = website["URL"] as? String {
self.loadAddressURL(name)
Run Code Online (Sandbox Code Playgroud)
我觉得我错过了一些小事.如果有更好的方法,我会喜欢建议.URL返回此JSON
{
"WEB" : [
{
"URL" : "http://www.google.com"
}
]
}
Run Code Online (Sandbox Code Playgroud)
但如果我能简化它,我会喜欢它
{"URL":"http://www.google.com"}
Run Code Online (Sandbox Code Playgroud) 我收到此错误:"尝试运行此代码块时,键入'Any'没有下标成员":
init(snapshot: FIRDataSnapshot) {
key = snapshot.key
itemRef = snapshot.ref
if let postContent = snapshot.value!["content"] as? String { // error
content = postContent
} else {
content = ""
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在寻找答案,找不到用FireBase解决这个问题的答案.我该如何解决这个错误?
我正在使用Facebook SDK登录并在我的终端获取数据但无法解决问题我面临与语法相关的挑战
func fetchProfile() {
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: { (connection, user, requestError) -> Void in
if requestError != nil {
print(requestError)
return
}
var email = user["email"] as? String
let firstName = user["first_name"] as? String
let lastName = user["last_name"] as? String
self.nameLabel.text = "\(firstName!) \(lastName!)"
var pictureUrl = ""
if let picture = user["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String {
pictureUrl = …Run Code Online (Sandbox Code Playgroud)