i'm trying build personal app fun using grace note api movies playing in theaters near me (json format). i'm able make call server , display movies showing. however, i'm trying display showtimes, embedded deeper in json. i'll try explain best can, json response is:
theres root array of x dictionaries (however many movies in theater)
inside each dictionary key 'title' i'm getting , displaying in table (working correctly).
what i'm getting stuck on inside each root dictionary, theres dictionary named 'showtimes'. inside dictionary theres x amount of dictionaries (however many times movie plays in theater). inside each of these dictionaries theres key 'datetime' actual showtime want , store array each movie. idea display '12:30, 2:45, 5:00,7:30' in tableview cells detail text label.
thank in advance!
this helpful resource you. first of all, let me recommend use swiftyjson. ease work json. question... (see comments in code clarity)
for (index: string, subjson: json) in json { // whole json array, "[" in beginning indicates (index: string, subsubjson: json) in subjson["showtimes"] { // in "showtime" arrays: self.<your array>.append(gettime(subsubjson["datetime"].string!)) // append processed value key "datetime" <your array> } } func gettime(input:string) -> string { let dateformatter = nsdateformatter() dateformatter.dateformat = "yyyy-mm-dd't'hh:mm" let date = dateformatter.datefromstring(input) let calendar = nscalendar.currentcalendar() let comp = calendar.components((.calendarunithour | .calendarunitminute), fromdate: date!) let hour = comp.hour let minute = comp.minute return ("\(hour):\(minute)") } this give you:
10:15 12:20 14:25 16:30 18:35 20:40 10:20 12:30 14:40 16:50 19:0 // not sure why happens :(
Comments
Post a Comment