JSON 을 통 해 리그 정보 획득

let url = "http://op.juhe.cn/onebox/football/league?key=API_KEY=%e8%8b%b1%e8%b6%85"   //api  
do{
    //1.    url   NSRUL
    //2.  NSURL       ,   NSData  ,   jsonData
    let jsonData = NSData(contentsOf: NSURL(string: url)  as! URL)
    
    
    //  JSONSerialization NSData      JSON   (      JSON             ,            NSDictionary。            ,            NSArray  。)
    let json = try JSONSerialization.jsonObject(with: jsonData as! Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? NSDictionary
    //print(json)
    
    
    let league_result = json?["result"] as? NSDictionary
    let league_name = league_result?["key"] as! String //           
    let league_tabs = league_result?["tabs"] as? NSDictionary  //    ,      
    let league_views = league_result?["views"] as? NSDictionary
    
    //   
    let league_sheshoubang = league_views!["sheshoubang"] as! NSArray  //     
    for i in 0...9 {
        let sheshoubangindex = league_sheshoubang[i] as! NSDictionary
        let sheshou_name = sheshoubangindex["c2"]!  //       
        let sheshou_team = sheshoubangindex["c3"]!  //         
    }
    
    //   
    let league_jifenbang = league_views!["jifenbang"] as! NSArray
    for i in 0...9{
        let jifenbangindex = league_jifenbang[0] as! NSDictionary
        let jifen_name = jifenbangindex["c2"]!
    }

    //      
    let league_saicheng1 = league_views!["saicheng1"] as! NSArray
    for i in 0...9 {
        let saichengname = league_saicheng1[i] as! NSDictionary
        let saichengzhu = saichengname["c4T1"]!
        let saichengke = saichengname["c4T2"]!
        let saichengdate = saichengname["c2"]!
        let saichengtime = saichengname["c3"]!
    }
    
    //      
    let league_saicheng2 = league_views!["saicheng2"] as! NSArray
    for i in 0...9 {
        let saichengname = league_saicheng2[i] as! NSDictionary
        let saichengzhu = saichengname["c4T1"]!
        let saichengke = saichengname["c4T2"]!
        let saichengdate = saichengname["c2"]!
        let saichengtime = saichengname["c3"]!
    }
    
 
}  catch {
    NSLog("JSON    ")
}

좋은 웹페이지 즐겨찾기