I get a error and I do not know why ... can anyone help me? I am despairing! No other post has helped me. Thank you very much in advance for your answer!!
PS: I get the error only when I try to run on my own iphone
func parseJson() {
let username: String = UserDefaults.standard.value(forKey: "username")! as! String
let url=URL(string:"https://website.de")
do {
let allBetData = try Data(contentsOf: url!)
let allBet = try JSONSerialization.jsonObject(with: allBetData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
if let arrJSON = allBet["bets"] as! [String : AnyObject]? {
for index in 0...arrJSON.count-1 {
let aObject = arrJSON[index] as [String : AnyObject]?
header.append(aObject["header"] as! String)
rowDescription.append(aObject["rowDescription"] as! String)
bodytext.append(aObject["bodytext"] as! String)
}
}
print("data loaded")
self.tableView.reloadData()
}
catch {
self.logout()
}
}
Ok, this is totally fundamental and you need to make sure you get this.
One line at a time...
if let arrJSON = allBet["bets"] as! [String : AnyObject]? {
Here you say, "I am making this thing called arrJSON, it's a dictionary with string keys and any sort of value". Good so far? Then you...
for index in 0...arrJSON.count-1 {
"I would like to loop the number of times that there are items"...
let aObject = arrJSON[index] as [String : AnyObject]?
"...and get the object who's key is this number".
Do you understand the problem now?