Swift:Alamofire与HandyJSON

Alamofire.request(url, method: .post, parameters: nil).responseString { (response) in
            
            if response.result.isSuccess {
                
                if let jsonString = response.result.value {
                    
                    /// json转model
                    /// 写法一:responseModel.deserialize(from: jsonString)
                    /// 写法二:用JSONDeserializer.deserializeFrom(json: jsonString)
                    if let responseModel = MZHomeModel.deserialize(from: jsonString) {
                        
                        /// model转json 为了方便在控制台查看
                        print(responseModel.toJSONString(prettyPrint: true)!)
                      
                        /// 遍历responseModel.data
                        responseModel.data?.findActivitys.forEach({ (model) in
                            print(model.url!);
                        })
                        
                    }
                }
            }
        }
Swift必须的开源库:
platform :ios, '9.0'

target '你的工程名字' do
  use_frameworks!

  pod 'Kingfisher'
  pod 'Alamofire'
  pod 'HandyJSON'
  pod 'SnapKit'
  pod 'Reusable'

end

在终端输入以下命令,指定一下 Swift 版本

echo "4.0" >> .swift-version

你可能感兴趣的:(Swift:Alamofire与HandyJSON)