欢迎光临
我们一直在努力

JSON Parsing With Codable

建站超值云服务器,限时71元/月

JSON Parsing With Codable

项目介绍:

AlamofireCodable: An extension to Alamofire which automatically converts JSON response data into swift objects using Codable.
This project is heavily inspired by the popular AlamofireObjectMapper.

image.png

Installation

AlamofireCodable can be added to your project using CocoaPods by adding the following line to your Podfile:

pod 'AlamofireCodable'

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Xcode 9+ , Swift 4+

Usage

Given a URL which returns weather data in the following form:

{  
   "data":{  
      "location":"Toronto, Canada",
      "three_day_forecast":[  
         {  
            "conditions":"Partly cloudy",
            "day":"Monday",
            "temperature":20
         },
         {  
            "conditions":"Showers",
            "day":"Tuesday",
            "temperature":22
         },
         {  
            "conditions":"Sunny",
            "day":"Wednesday",
            "temperature":28
         }
      ]
   }
}

You can use the extension as the follows:

import AlamofireCodable

        let form = WeatherForm()
        Alamofire.request(
                form.url,
                method: HTTPMethod.get,
                parameters: form.parameters(),
                encoding: form.encoding(),
                headers: form.headers()
            )
            .responseObject(keyPath: "data",completionHandler: { (response: DataResponse<Weather>) in
                switch response.result {
                case .success(let object):
                    debugPrint("



赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » JSON Parsing With Codable
分享到: 更多 (0)