ios - I need to fetch a JSON in a URL -
i read url loading system:
can't figure out class use , how use it.
i suggest using third party framework alamofire native swift networking rather complicated, beginners, because swift type-safe language , json object can have nesting etc. can seen after fetching of object.
the thing alamofire can installed cocoapods , actively being developed. here example of request made alamofire's 4.0 version swift 3 fetch json object url called yoururl:
alamofire.request("https://yoururl").responsejson { response in print(response.request) // original url request print(response.response) // http url response print(response.data) // server data print(response.result) // result of response serialization if let json = response.result.value { print("json: \(json)") // json here } }
you can use third party framework swiftyjson parse json retrieve - if has complicated structure. sadly there no update in sight swift 3 guess have wait , see how pans out.
edit: there unofficial swift 3 branch swiftyjson, can installed cocoapods (it works me on ios10/swift 3):
pod 'swiftyjson', git: 'https://github.com/baiduhidevios/swiftyjson.git', branch: 'swift3'
Comments
Post a Comment