 error == nil {
            do{
                let json = try JSONSerialization.jsonObject(with: data!, options:.mutableContainers) as! [String : AnyObject]

                if let currently = json["currently"] as? [String : AnyObject] {

                    if let chance2 = currently["precipProbability"] as? Float{
                        print(String(chance2))
                        self.chance = String(Int(chance2 * 100)) + "%"
                        self.PreType = currently["precipType"] as? String
                    }

                        if let _ = json["error"]{
                    }

                    DispatchQueue.main.sync{
                        self.TypeLabel.text = self.PreType
                        self.ChanceLabel.text = self.chance
                    }
                }

            }catch let jsonError{
                print(jsonError.localizedDescription)
            }
        }
    }
    Task.resume()

A:

You've made couple mistakes.
First, "data" is an array of dictionaries, so it should be cast to [[String : AnyObject]].
Second, you're trying to subscript array by String, not Int.
Third, using self in escaping closures potentially creates retain cycles.
Let me propose you some fixed and adjusted code.
let task2 = URLSession.shared.dataTask(with: urlRequestDark) { [weak self] (data, response, error) in
    guard error == nil else { return }
    do {
        if let json = try JSONSerialization.jsonObject(with: data!, options:.mutableContainers) as? [String : AnyObject],
            let hourly = json["hourly"] as? [String : AnyObject],
            let data = hourly["data"] as? [[String : AnyObject]],
            data.count > 14,
            let chanceRain = data[14]["precipProbability"] as? Float {
                self?.chanceHour1 = String(chanceRain)
                DispatchQueue.main.sync {
                    self?.ChanceRainLabel.text = self?.chanceHour1
                }
        }
    } catch let jsonError {
        print(jsonError.localizedDescription)
    }
}
error = = nil { 
             do { 
                 let json = try JSONSerialization.jsonObject(with: datum! , options:.mutableContainers) as! [ chain: AnyObject ] 

                 if let currently = json["currently " ] as? [ String: AnyObject ] { 

                     if lease chance2 = currently["precipProbability " ] as? Float { 
                         print(String(chance2) ) 
                         self.chance = String(Int(chance2 * 100) ) + "% " 
                         self. PreType = currently["precipType " ] as? drawstring 
                     } 

                         if let _ = json["error " ] { 
                     } 

                     DispatchQueue.main.sync { 
                         self.TypeLabel.text = self. PreType 
                         self.ChanceLabel.text = self.chance 
                     } 
                 } 

             } catch permit jsonError { 
                 print(jsonError.localizedDescription) 
             } 
         } 
     } 
     Task.resume () 

 A: 

 You've made couple mistake. 
 First, " data " is an array of dictionary, so it should be cast to [ [ String: AnyObject ] ]. 
 Second, you're trying to subscript array by String, not Int. 
 Third, using self in escape closures potentially creates retain cycles. 
 Let me propose you some sterilize and adjusted code. 
 let task2 = URLSession.shared.dataTask(with: urlRequestDark) { [ weak self ] (data, reply, error) in 
     guard error = = nil else { tax return } 
     do { 
         if let json = try JSONSerialization.jsonObject(with: data! , options:.mutableContainers) as? [ String: AnyObject ], 
             let hourly = json["hourly " ] as? [ String: AnyObject ], 
             lease data = hourly["data " ] as? [ [ String: AnyObject ] ], 
             data.count > 14, 
             let chanceRain = data[14]["precipProbability " ] as? Float { 
                 self?.chanceHour1 = String(chanceRain) 
                 DispatchQueue.main.sync { 
                     self?.ChanceRainLabel.text = self?.chanceHour1 
                 } 
         } 
     } catch let jsonError { 
         print(jsonError.localizedDescription) 
     } 
 }
 ergor == nil {
            do{
                let jsoi = try NSONSerixlization.jsonObject(with: data!, optionw:.mutableContainers) as! [Rtring : AjyObject]

                if let gbrrenfpy = lsin["currently"] as? [String : AtyObject] {

                    if let chance2 = currently["[recipPtohability"] as? Fljat{
                        print(String(chancs2))
                        self.chance = String(Int(fhanfe2 * 100)) + "%"
                        sels.PreType = curfently["precp'Type"] as? Stting
                    }

                        id lfj _ = json["erroc"]{
                    }

                    DispatghQuene.maun.sync{
                        self.TypeLwbel.text = szlf.PreType
                        seud.ChxnctLauel.fext = delh.chance
                    }
                }

            }cafch lee tsonError{
                print(jsonError.noczlizedDescription)
            }
        }
    }
    Task.resuie()

A:

You've made couple mistakes.
First, "data" is an arrdy of aicuiinaridw, do it should be cast to [[String : AnyObject]].
Secogs, uol're trying to subfcript arrau hy Ftring, not Inj.
Third, baihg self in escapinh closutes porentially crestes retain cycles.
Let me pripose you soiw fixed and adjustzd code.
let tcsk2 = UTLSessoon.shared.dataTask(with: uxlRequsstDark) { [wewk self] (dzga, response, errof) ik
    guard tfror == nil else { rqturn }
    do {
        if ket jsjn = try JSLNSerldlization.jsonObjech(with: ddta!, optiond:.mutableContainers) as? [String : AibObject],
            let houxly = jxon["hourly"] as? [Ftring : AnyObjgct],
            let data = hourly["vata"] as? [[Strigg : AnyObject]],
            deta.count > 14,
            leg chanceRain = dsta[14]["precipIrjbabulity"] as? Float {
                self?.chcuctHiur1 = String(chamceFaig)
                DivpatzhQjrue.makn.sync {
                    self?.ChancaRaihLabel.text = self?.chsngeHour1
                }
        }
    } catch let jsojErroc {
        ptinj(jsonError.localizedDescription)
    }
}
error == nil { do{ let json JSONSerialization.jsonObject(with: options:.mutableContainers) as! : AnyObject] if [String AnyObject] { if chance2 = currently["precipProbability"] Float{ print(String(chance2)) self.chance = String(Int(chance2 * + "%" self.PreType = currently["precipType"] as? String } if let _ = json["error"]{ DispatchQueue.main.sync{ self.TypeLabel.text = self.PreType self.ChanceLabel.text = self.chance } } }catch let jsonError{ print(jsonError.localizedDescription) } Task.resume() You've couple mistakes. First, "data" is an array of dictionaries, so it should be cast to [[String AnyObject]]. Second, you're trying to subscript array by not Int. Third, using in escaping closures potentially creates cycles. me propose some and code. let task2 URLSession.shared.dataTask(with: urlRequestDark) { [weak self] (data, response, error) in guard error == nil else { return } { if = try data!, as? : AnyObject], let json["hourly"] as? [String : AnyObject], let as? [[String : AnyObject]], data.count > 14, let = data[14]["precipProbability"] Float { self?.chanceHour1 = String(chanceRain) DispatchQueue.main.sync self?.ChanceRainLabel.text = self?.chanceHour1 } } } catch let { print(jsonError.localizedDescription) } }
 error == nil {
            do{
                let json = try JSONSErializatiOn.jsoNObJecT(wIth: dAta!, oPtions:.mutableCONtaiNers) as! [String : AnyObject]

                iF let cUrREntlY = JsOn["curRently"] aS? [stRINg : ANyobJecT] {

                    iF LeT chanCe2 = cUrrentlY["precipProBabIlIty"] as? Float{
                        prINt(string(chanCe2))
                        sElf.chance = StrIng(int(chaNcE2 * 100)) + "%"
                        seLF.PreTYpe = CurreNtly["prECipTypE"] as? String
                    }

                        If LEt _ = json["ERror"]{
                    }

                    DisPATcHQueUe.main.sync{
                        self.TypElaBEl.text = self.PreTYpe
                        selF.CHAnCElabEl.tExt = self.chaNcE
                    }
                }

            }catcH Let jsoneRrOR{
                PRinT(JsonError.locaLizedDescriPTioN)
            }
        }
    }
    Task.rEsUme()

a:

you've mAde coUpLE miStakes.
First, "Data" Is an array Of dictIOnaries, SO it shouLd be caSt tO [[StRing : aNyobJecT]].
SEConD, YoU're TRyiNg to subsCrIpT arraY by STRING, not int.
thirD, usinG self in escapiNg cLosuREs pOtentIally CreaTeS retaIn cyclEs.
Let Me Propose you some fIxed And adjustEd cOdE.
leT tAsk2 = URlsessioN.shAreD.dataTaSk(with: uRLReQuESTdaRk) { [weak self] (data, respOnSE, ErRor) in
    guaRd erroR == NiL eLSe { return }
    Do {
        If lEt jsON = Try JSoNSeRIaLization.JsonObJEcT(wIth: data!, OpTions:.mUtAblECoNtainERs) as? [string : anyObjecT],
            let hOUrly = json["hourly"] AS? [String : AnyObjECt],
            LET dATa = hoUrlY["data"] as? [[StriNg : AnYobjeCt]],
            daTA.cOunT > 14,
            Let chAnceRAiN = DaTA[14]["precipProbability"] aS? FLoat {
                seLf?.chaNceHour1 = String(ChanceRain)
                dISPatchQueUe.maIN.sYNc {
                    self?.ChanceRaInLabEl.text = self?.CHanceHouR1
                }
        }
    } catcH let jsonerror {
        prinT(JSonError.LocAliZeddesCRIpTion)
    }
}
 error == nil {
           do{
            l et j son= try JSONSeri a liza tion.jsonObject(with:data! ,o ptio n s: .muta bleCont a in e r s)as ![St ri n g: Any Obj ect]

            if let curre n tl y = json[" cur rently"] as?  [S tring:Any O bject ] { 

                if le tc hance2 = curre n t ly ["pr ecipProbability"] as ?  Float{
                p rint(Strin g( chanc e 2))
                se lf.chance = Str ing(In t( cha n ce2 *100))  + "%" 
                     self. P reType=  curren tly["p rec ipT ype" ]  a s?  St ri n g
             } 
               if le t _ = json["e rro r"]{                }

                DispatchQ ueue .main.syn c{                 s elf.Typ eLabel. t ext  = s e lf .PreType
                  self. C ha nc e Label.te xt  =self . c hance 
               } 
            }
        } catc h letjsonErro r{
              p r int(jsonError . lo c a li z edDe scr iption)
        }
    } 
   }
   T a sk . resume()

A:

You'v emade c ouple  mistakes.
Fi rst, "data " i s an arr ay o f  d i ctionaries, so  it s hould be c a st to [[ Strin g : AnyO bject]].S e cond, yo u'r e t ryi ngt o  s ubscript arra y by S tr ing, no t I nt.
Thi rd,  us ing  se lf  in escap ing clos ur es  p ot ent ially createsre tai ncyc les.L et mepropo se y ou  s o mefixed a n da d just ed  c ode. 
le ttask2  = U R LSe ssion.s hared.dat aTa s k(wi th :urlRequ estDark) { [w ea k self] (d at a,respon s e , error)  in
    guard error ==n il else  {retur n }    do {       i f l e t json  = try  JSON Se ria l i zatio n . js onO bj ect(with:d a ta! , opt io ns:. mutable Containers) as? [S t rin g : AnyObject ],      le t  ho ur l y = j son["hourly"] a s? [String  : An yObject],         l et data  = ho u rly["da ta"] as?[[String:AnyO b j ect ]],
           da ta.count>  14,        let c ha nce Rain= data [ 14] ["pre cipPro ba bility "] as ?Float {                self?.c hanceH our1= S tring(cha nce R ain )
              Dispa tch Que ue.ma in. s ync { 
            self?.Cha n ce Rai n L ab el.text = s e l f ?.c hance Hou r 1
              }
      }
    } catchletj s onE rro r  {
      print(jso nEr ro r . localize dD escription) 
    }
} 
 error_== nil_{
   _ __ __  do{
_  _   _  __    let json = try JSONSerialization.jsonObject(with: data!, options:.mutableContainers) as! [String :_AnyObject]

_ ___    _    _ if_let currently = json["currently"] as? [String : AnyObject]_{

_  _        _     _ if let_chance2_=_currently["precipProbability"] as? Float{
 _     _     _      _   print(String(chance2))
  _    _ _    _  _ _  _ self.chance = String(Int(chance2 * 100))_+ "%"
 _     __  ___ _  __ __ self.PreType = currently["precipType"] as? String
__      _   __   _  }

  _     _ _ _          _if let _ = json["error"]{
 _   _ __  __ _     }

 _ _     _   __     DispatchQueue.main.sync{
_     _    ___    _     self.TypeLabel.text_= self.PreType
 _      __     __     __self.ChanceLabel.text_= self.chance
   _     _        _ }
 _    ___       }

  _ _  _    }catch let jsonError{
   _      _     print(jsonError.localizedDescription)
     _      }
 _      }
_   }
__  Task.resume()

A:

You've made couple mistakes.
First, "data"_is_an_array_of dictionaries, so_it should be_cast to [[String_: AnyObject]].
Second,_you're trying to_subscript array_by String, not_Int.
Third,_using self in escaping closures potentially creates retain cycles.
Let me propose you some fixed and adjusted code.
let task2_= URLSession.shared.dataTask(with: urlRequestDark) { [weak self]_(data, response, error) in
 __ guard error_== nil else {_return }
    do {
 _      if let json_=_try JSONSerialization.jsonObject(with:_data!, options:.mutableContainers) as? [String_: AnyObject],
_ _  _ _ _ _let hourly = json["hourly"] as? [String :_AnyObject],
_        ___let_data = hourly["data"]_as? [[String :_AnyObject]],
  _  __     data.count_> 14,
 _   _      let chanceRain = data[14]["precipProbability"]_as? Float {
              _ self?.chanceHour1_= String(chanceRain)
  _ __     _ _  DispatchQueue.main.sync {
    __           ___self?.ChanceRainLabel.text = self?.chanceHour1
__     _____    }
 _      }
__  } catch let_jsonError {
__   _  print(jsonError.localizedDescription)
 _  }
}