ios - read the specific data from the JSON file and load on tableView in swift -
have text file in project put json data read data problem occur when specific field read program crash fatal error andy 1 me code let path = nsbundle.mainbundle().pathforresource("days", oftype:"json") let jsondata = nsdata(contentsoffile:path!) // println(jsondata) var jsonresult: nsdictionary = nsjsonserialization.jsonobjectwithdata(jsondata!, options: nsjsonreadingoptions.mutablecontainers, error: nil) as! nsdictionary // println(jsonresult) var = 0 ; < jsonresult .valueforkey("monday")!.count ; i++ { arrdic!.addobject((jsonresult.valueforkey("monday") as! nsarray).objectatindex(i)) println( arrdic!.addobject((jsonresult.valueforkey("monday") as! nsarray).objectatindex(i)) func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("ahmad") as! tableviewcellahmad cell.labeltxt.text = arrdic[indexpath.row].valueforkey("title") as? string cell.detaillbltxt.text = arrdic[indexpath.row].valueforkey("details") as? string return cell
thats code read data json format of data when want fetch monday crash program error fatal error
{ "monday": [ { "title": "test driven development", "speaker": "jason shapiro", "time": "9:00 am", "room": "matisse", "details": "explore topics , tools related test driven development." }, { "title": "java tools", "speaker": "jim white", "time": "9:00 am", "room": "rothko", "details": "discuss latest set of tools used ease software development." } ], "tuesday": [ { "title": "mongodb", "speaker": "davinmickelson", "time": "1: 00pm", "room": "picasso", "details": "learnabout\"nosql\"databases." }, { "title": "debuggingwithxcode", "speaker": "jasonshapiro", "time": "1: 00pm", "room": "vangogh", "details": "exploredifferentpatternsfordebuggingyouriosapps." } ], "wednesday": [ { "title": "scrum master", "speaker": "davin mickelson", "time": "1:00 pm", "room": "matisse", "details": "learn roles , responsibilities of scrum master" }, { "title": "design patterns", "speaker": "jim white", "time": "1:00 pm", "room": "rothko", "details": "apply best practices , sound architectures software design." } ]
} thats json format want fetch title , details
Comments
Post a Comment