ios - How can I process multiple links of JSON data? -


the code works perfectly. problem that, after trying while, cannot figure out how make program process second link of different json data.

here viewdidload goes on:

override func viewdidload() {     super.viewdidload()          var err: nserror?         let urlpath: string = "https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/" + searchfielddatapassed + "?api_key=(removed private api key obvious reasons"         var url: nsurl = nsurl(string: urlpath)!         let session = nsurlsession.sharedsession()         let task = session.datataskwithurl(url) { data, response, error in              // cast response nshttpurlresponse , switch on statuscode if             if let httpresponse = response as? nshttpurlresponse { switch httpresponse.statuscode { case 200..<300: println("ok") default: println("not ok") } }              // parse json using nsjsonserialization if you've got data             if let jsonresult = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers, error: &err) as? nsdictionary,             let include = jsonresult.objectforkey(self.searchfielddatapassed) as? nsdictionary {                      if let summlevel = include[ "summonerlevel" ] as? nsnumber {                          dispatch_async(dispatch_get_main_queue()) {                              self.summonerlevel.text = "\(summlevel.integervalue)"                             println("summoner level: \(summlevel.integervalue)")                          }                     }                      if let proficonid = include[ "profileiconid" ] as? nsnumber {                          dispatch_async(dispatch_get_main_queue()) {                              self.profileiconid.text = "\(proficonid.integervalue)"                             println("profile icon id: \(proficonid.integervalue)")                          }                     }                      if let idnum = include [ "id" ] as? nsnumber {                          dispatch_async(dispatch_get_main_queue()) {                              self.idnumber = idnum                             println("id number: \(self.idnumber)")                          }                 }             }           // spawn off network call here if     }     task.resume()   } 

that secondviewcontroller processing goes on json , displayed.

here json data i'm processing (for first json parsing):

{"soon2challenger":{"id":43993167,"name":"soon2challenger","profileiconid":844,"summonerlevel":30,"revisiondate":1435549418000}} 

all of works fine, now, want process json data takes id first parsed json data , uses in link process more data, output, part of it, screen.

second json data:

{"summonerid":43993167,"playerstatsummaries":[{"playerstatsummarytype":"aramunranked5x5","wins":25,"modifydate":1423007927000,"aggregatedstats":{"totalchampionkills":676,"totalturretskilled":20,"totalassists":991}},{"playerstatsummarytype":"cap5x5","wins":15,"modifydate":1429065922000,"aggregatedstats":{"totalchampionkills":312,"totalminionkills":4885,"totalturretskilled":31,"totalneutralminionskilled":511,"totalassists":216}},{"playerstatsummarytype":"coopvsai","wins":28,"modifydate":1421882181000,"aggregatedstats":{"totalchampionkills":266,"totalminionkills":2802,"totalturretskilled":50,"totalneutralminionskilled":385,"totalassists":164,"maxchampionskilled":0,"averagenodecapture":0,"averagenodeneutralize":0,"averageteamobjective":0,"averagetotalplayerscore":49,"averagecombatplayerscore":0,"averageobjectiveplayerscore":49,"averagenodecaptureassist":0,"averagenodeneutralizeassist":0,"maxnodecapture":0,"maxnodeneutralize":0,"maxteamobjective":0,"maxtotalplayerscore":49,"maxcombatplayerscore":0,"maxobjectiveplayerscore":49,"maxnodecaptureassist":0,"maxnodeneutralizeassist":0,"totalnodeneutralize":0,"totalnodecapture":0,"averagechampionskilled":0,"averagenumdeaths":0,"averageassists":0,"maxassists":0}},{"playerstatsummarytype":"coopvsai3x3","wins":15,"modifydate":1421882181000,"aggregatedstats":{"totalchampionkills":140,"totalminionkills":1114,"totalturretskilled":9,"totalneutralminionskilled":449,"totalassists":91}},{"playerstatsummarytype":"odinunranked","wins":1,"modifydate":1421882181000,"aggregatedstats":{"totalchampionkills":31,"totalassists":45,"maxchampionskilled":10,"averagenodecapture":4,"averagenodeneutralize":4,"averageteamobjective":0,"averagetotalplayerscore":843,"averagecombatplayerscore":268,"averageobjectiveplayerscore":575,"averagenodecaptureassist":3,"averagenodeneutralizeassist":1,"maxnodecapture":6,"maxnodeneutralize":7,"maxteamobjective":2,"maxtotalplayerscore":1468,"maxcombatplayerscore":529,"maxobjectiveplayerscore":939,"maxnodecaptureassist":5,"maxnodeneutralizeassist":2,"totalnodeneutralize":22,"totalnodecapture":25,"averagechampionskilled":5,"averagenumdeaths":5,"averageassists":8,"maxassists":19}},{"playerstatsummarytype":"rankedsolo5x5","wins":116,"losses":120,"modifydate":1433630047000,"aggregatedstats":{"totalchampionkills":1699,"totalminionkills":33431,"totalturretskilled":219,"totalneutralminionskilled":6501,"totalassists":1969}},{"playerstatsummarytype":"rankedteam3x3","wins":0,"losses":0,"modifydate":1377726216000,"aggregatedstats":{}},{"playerstatsummarytype":"rankedteam5x5","wins":3,"losses":0,"modifydate":1383784473000,"aggregatedstats":{"totalchampionkills":28,"totalminionkills":636,"totalturretskilled":6,"totalneutralminionskilled":101,"totalassists":41}},{"playerstatsummarytype":"unranked3x3","wins":9,"modifydate":1421882181000,"aggregatedstats":{"totalchampionkills":90,"totalminionkills":1427,"totalturretskilled":11,"totalneutralminionskilled":428,"totalassists":105}},{"playerstatsummarytype":"urf","wins":4,"modifydate":1435024847000,"aggregatedstats":{"totalchampionkills":68,"totalminionkills":642,"totalturretskilled":14,"totalneutralminionskilled":182,"totalassists":55}},{"playerstatsummarytype":"unranked","wins":566,"modifydate":1435549418000,"aggregatedstats":{"totalchampionkills":8419,"totalminionkills":128213,"totalturretskilled":960,"totalneutralminionskilled":26117,"totalassists":7812}}]} 

heres link of second json data want parse (just adding it, useful, not sure): https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/43993167/summary?season=season2015&api_key=(took-out-my-private-api-key-for-obvious-reasons)

the link doesn't work because have keep api key private myself, json data displays right above link, result if use link api key.

just restate, process second part (above of this) of json data, not understand how process multiple links of json. have first json data parsed, unable parse second json data.

i believe apple deprecating nsurlconnection. take @ nsurlsession. using it, can pass in completion block takes 3 arguments: nsdata?, nsurlresponse?, , nserror?. data object contains json can pass json serializer. after that, if need make network call, call inside completion block nsurlsession data task. alamofire great framework, don't need provides, , adds complexity app if goes wrong or doesn't behave way intend/understand, may not understand why. if want keep simple , under control, use nsurlsession.

let session = nsurlsession.sharedsession() let task = session.datataskwithurl(url) { data, response, error in     // cast response nshttpurlresponse , switch on statuscode if     // parse json using nsjsonserialization if you've got data     // spawn off network call here if } task.resume() // or in swift 2, task?.resume() 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -