Search This Blog

Thứ Năm, 17 tháng 8, 2017

Lấy chuổi Json về

let url = URL(string: "http://api.tuoitre.vn/app/catpage?token=dee03981&cid=13&limit=13")
        
        var req = URLRequest(url: url!)
        req.httpMethod = "POST"
        
        URLSession.shared.dataTask(with: req , completionHandler: { (data, res , err) in
            
            // code
           // print( String(data: data!,encoding: .utf8 )! )
            do{
                let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [AnyObject]
                for row in json {
                    
                    print( row["object_id"] as! String  )
                    print( row["title"] as! String  )
                    
                }
            }catch{
                
            }
            

        }).resume()

Không có nhận xét nào:

Đăng nhận xét