1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() NetWorkingTool.shendInstance.getData(url: "https://www.v2ex.com/api/nodes/show.json?name=python", dataBlock: { (responseData) in //返回的是数组 guard responseData is [String: Any] else { let dataArray = responseData as! Array<[String: Any]> for dict in dataArray { print(dict["title"]!, dict["id"]!) } return } //返回的是字典 guard responseData is [String: Dictionary<String, Any>] else { let dataArray = responseData as! Dictionary<String, Any> for value in dataArray { print(type(of: value)) } return } }) { (error) in print(error) } } }
|