javascript - JSON app not responding with web code -


i have written out json code, uploaded ftp server, , used in json app. have written codes app in xcode. use swift. problem when run app, nothing returned in uitableview. how make text appear in ios simulator?

update

i have followed scriptable's guidance, , new error in xcode:

error domain=nscocoaerrordomain code=3840 "invalid value around character 0." userinfo={nsdebugdescription=invalid value around character 0.}

update ended

here json web code (in .json file):

         {"items":[{              "title" : "big little lies book review",             "date" : "wednesday 3rd february, 2016",             "content" : "few spoilers ahead. finished reading big little lies liane moriarty few days ago, , haven't stopped thinking since! book gripping,and characters (what love most) different. have madeline mackenzie, bubbly, bright 40 year old; celeste white, beautiful, weak lady married rich businessman; , jane chapman, quiet, 24-year old mum mysterious past. novel set in pirriwee, australia. these characters' children join pirriwee public, beginning kindergarden. previous orientation day drama still lingers between mothers, victim's mum, renata klein, , so-called bully's mum, jane (at point, still unaware of bully is.) story leads annual trivia night of school, end of each chapter showing small extract of other mothers recounting night. detective questioning them regard murder. in these extracts, see there conflict between madeline, celeste, , jane one, , other mothers (not fathers.) moriarty makes connections between each character, each conflict, , each personal story. read book, see these connections strengthening, being vividly bonded @ end. themes of book bullying, domestic violence, , teenage problems. clearer , more elaborate others. shows great research reading various books on topic of domestic violence, burden on celeste. each main character (jane, celeste, , madeline) portray own emotional conflict, being more able share others. in end, these problems solved, naturally, should, 1 problem's answer harsher others. rating fantastic book 4.5 stars, , recommend older teenagers , adults. book adaptation great on big screen. big little lies has been envisaged shown in 2017 on hbo, , consists of 8 episodes."         },{              "title" : "new allegiant poster released",             "date" : "wednesday 3rd february, 2016",             "content" : "a new allegiant poster has been released, , have added photos. shows shailene's character tris on swirling staircase (much dnastrand),and 4 (theo james), caleb prior (ansel elgort), christina (zoe kravitz), , peter (miles teller.) new slogan has been added, saying 'whatmakes different ties together.' allegiant out in cinemas on march 18th, 2016. world premiere in new york, being on march 14th (this not confirmed yet.)"         },{              "title" : "allegiant stills released",             "date" : "friday 29th january, 2016",             "content" : "some more allegiant stills have been released - if can't enough! 2 have obtained of shailene's character, tris, have been added allegiant gallery in photos."         },{              "title" : "new big little lies behind scenes photos",             "date" : "friday 29th january, 2016",             "content" : "with abundance of big little lies photos, yet have received more. of these first scene of book, shailene's character, jane, meets reese witherspoon's character, madeline. last day of shooting until april. filming being shot in monterey, california. of these photos have been added gallery."         },{              "title" : "the divergent fandom app",             "date" : "friday 29th january, 2016",             "content" : "as if fandom couldn't better, divergent series released app fandom group on. app contains latest news , stills regarding divergent films. user @totallyshailene, feel free contact me! once again, allegiant out on march 18th, 2016, it's world premiere happening in new york, no date yet announced."         },{              "title" : "more big little lies news",             "date" : "friday 22nd january, 2016",             "content" : "filming continue 'big little lies' january 25th january 29th in monterey, california. filming return in april 2 weeks , wrap in may. show's executive producer has said post-production last approximately 6 months, , show air in 2017. 'big little lies' book-to-tv adaptation, focusing on 3 mothers played shailene woodley, reese witherspoon, , nicole kidman."         },{              "title" : "allegiant twitter q&a",             "date" : "friday 22nd january, 2016",             "content" : "we incredibly excited when divergent series on twitter (@divergent) said have q&a on twitter shailene woodley , theo james (tris , 4 respectively.) shai , theo answered great questions, of can see on divergent series' twitter. shailene talked can forward in allegiant, , gave few motivational words - always! these short videos have been added gallery in videos."         },{              "title" : "new allegiant trailer released",             "date" : "friday 22nd january, 2016",             "content" : "with fans in great anticipation, new 'allegiant' has been released! shows more emotional scenes of tris (shailene woodley) , 4 (theo james) , futuristic society of beyond wall. 'allegiant' out in cinemas on march 18th, 2016. new trailer has been added 'videos.'"         },{              "title" : "big little lies has offically began filming",             "date" : "sunday 10th january, 2016",             "content" : "'big little lies,' shailene woodley's new project, officially began filming in california on january 10th. have obtained many behind scenes images of have uploaded 'photos.'"         },{              "title" : "42nd annual people's choice awards",             "date" : "wednesday 6th january, 2016",             "content" : "the 42nd annual people's choice awards happened on wednesday 6th january, 2016. although shai wasn't in attendence, won award choice female action actress 'insurgent.' 'insurgent' nominated choice action movie, lost 'furious 7.' once again, successful night shailene!"         }]} 

here json app code:

import uikit  class newstableviewcontroller: uitableviewcontroller {  var siteurl = "http://annabellesykes.byethost11.com/shailenewoodleyfansappjson.html" var items = [item]()  override func viewdidload() {     super.viewdidload()     getlatestnews() }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: - table view data source  override func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return items.count }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! newstableviewcell      // configure cell...     cell.titlelabel.text = items[indexpath.row].title     cell.datelabel.text = items[indexpath.row].date     cell.contentlabel.text = items[indexpath.row].content      return cell }  func getlatestnews() {      let request = nsurlrequest(url: nsurl(string: siteurl)!)     let urlsession = nsurlsession.sharedsession()     let task = urlsession.datataskwithrequest(request, completionhandler: {         (data, response, error) -> void in          if let error = error {             print(error)             return         }          if let data = data {             self.items = self.parsejsondata(data)              nsoperationqueue.mainqueue().addoperationwithblock({ () -> void in                 self.tableview.reloaddata()             })         }      })      task.resume() }  func parsejsondata(data: nsdata) -> [item] {      var items = [item]()      {          let jsonresult = try nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.allowfragments) as? nsdictionary          let jsonitems = jsonresult?["items"] as! [anyobject]         jsonitem in jsonitems {             let item = item()             item.title = jsonitem["title"] as! string             item.content = jsonitem["content"] as! string             item.date = jsonitem["date"] as! string             items.append(item)         }      } catch {         print(error)     }      return items } 

your current code webpage, create server side script generate , return valid json particular url or create .json file.

for example:

create blank file called example.json , put following in it

 { "items": [{     "title": "allegiant stills released",     "date": "friday 29th january, 2016",     "content": "some more allegiant stills have been released - if can't enough! 2 have obtained of shailene's character, tris, have been added allegiant gallery in photos." }, {     "title": "allegiant stills released",     "date": "friday 29th january, 2016",     "content": "some more allegiant stills have been released - if can't enough! 2 have obtained of shailene's character, tris, have been added allegiant gallery in photos." }, {     "title": "allegiant stills released",     "date": "friday 29th january, 2016",     "content": "some more allegiant stills have been released - if can't enough! 2 have obtained of shailene's character, tris, have been added allegiant gallery in photos." }, {     "title": "allegiant stills released",     "date": "friday 29th january, 2016",     "content": "some more allegiant stills have been released - if can't enough! 2 have obtained of shailene's character, tris, have been added allegiant gallery in photos." }] 

}

then upload server , in ios application use following url:

http://annabellesykes.byethost11.com/example.json

it worthwhile reading on generating json 'on demand' though, try http://www.tutorialspoint.com/json/json_php_example.htm. it's not best tutorial out there should give starting point , show looking for.

edit:

this code working me locally..

override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          let request = nsurlrequest(url: nsurl(string: "http://local.test-application/example.json")!)         let urlsession = nsurlsession.sharedsession()         let task = urlsession.datataskwithrequest(request, completionhandler: {             (data, response, error) -> void in              if let error = error {                 print(error)                 return             }              if let data = data {                  {                      let jsonresult = try nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.allowfragments) as? nsdictionary                      print(jsonresult)                      let jsonitems = jsonresult?["items"] as! [string:anyobject]                     jsonitem in jsonitems {                         print(jsonitem)                     }                  } catch {                     print(error)                 }               }          })          task.resume()      } 

with json file: https://filetea.me/t1s5uhgtdlcrnudtgqimt5mqw

also if using non https url's in project you'll need allowarbitaryloads... see http://iosdevtips.co/post/121756573323/ios-9-xcode-7-http-connect-server-error


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -