ios - I need to fetch a JSON in a URL -


i read url loading system:

https://developer.apple.com/library/ios/documentation/cocoa/conceptual/urlloadingsystem/urlloadingsystem.html#//apple_ref/doc/uid/10000165i

can't figure out class use , how use it.

errorsreenshot

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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -