2017-10-10 1 views
-2

J'ai un json avec des heures d'ouverture. sous cela est une liste d'heures. Je voudrais que la liste soit un tableau que j'ai traversé en tant qu'objet à l'index.comment créer nsarray à partir d'un tableau dans un dictionnaire ns?

"Hours_Of_Operation" = "{"daysofweek":"1", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"2", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"3", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"4", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"5", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"6", "open_time":"10:00:00", "close_time":"02:00:00"},{"daysofweek":"7", "open_time":"10:00:00", "close_time":"00:00:00"}"; 
+0

dire quelque chose au lieu de juste en bas de vote .. – ASH

+0

[{ "Hours_Of_Operation" = "{" DaysOfWeek ":" 1" , "open_time": "11:00:00", "CLOSE_TIME": "00 : 00: 00 "}, {" daysofweek ":" 2 "," open_time ":" 11:00:00 "," close_time ":" 00:00:00 "}, {" daysofweek ":" 3 ", "open_time": "11:00:00", "close_time": "00:00:00"}, {"daysofweek": "4", "open_time": "11:00:00", "close_time": "02:00:00"}, {"daysofweek": "5", "open_time": "11:00:00", "close_time": "02:00:00"}, {"daysofweek": "6 "," open_time ":" 10:00:00 "," close_time ":" 02:00:00 "}, {" daysofweek ":" 7 "," open_time ":" 10:00:00 "," close_time ":" 00:00:00 "}"}] – ASH

Répondre

2
//Your json should be like this 
{"Hours_Of_Operation" : [{"daysofweek":"1", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"2", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"3", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"4", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"5", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"6", "open_time":"10:00:00", "close_time":"02:00:00"},{"daysofweek":"7", "open_time":"10:00:00", "close_time":"00:00:00"}]} 

//Using this json you can parse data 
let arrayHoursOfOperation = yourJsonDictionary.objectForKey("Hours_Of_Operation") as! NSArray 

Vous pouvez utiliser ComponentSeparatedByString pour obtenir résultat souhaité. Vous avez même besoin de modifier ce code en fonction de vos besoins.

NSString *str = @"{"daysofweek":"1", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"2", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"3", "open_time":"11:00:00", "close_time":"00:00:00"},{"daysofweek":"4", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"5", "open_time":"11:00:00", "close_time":"02:00:00"},{"daysofweek":"6", "open_time":"10:00:00", "close_time":"02:00:00"},{"daysofweek":"7", "open_time":"10:00:00", "close_time":"00:00:00"}"; 
NSArray *arr = [str componentsSeparatedByString:@"{"]; 
+0

Salut tout .. J'utilise objectif - c – ASH

+0

Nupur - comment puis-je changer json résultat .. quand il vient de la suite. – ASH

+0

$ sql = "SELECT PARTNER_LOCATIONS. *, (SELECT GROUPE_CONCAT (CONCAT ('{\" dayofweek \ ": \"', LOCATIONS_BUSINESS_HOURS.dayofweek, '\ ", \" open_time \ ": \"', LOCATIONS_BUSINESS_HOURS.open_time, '\ ", \" close_time \ ": \"', LOCATIONS_BUSINESS_HOURS.close_time, '\ "}') FROM LOCATIONS_BUSINESS_HOURS O LOC LOCATIONS_BUSINESS_HOURS.location_id = '3' GROUP BY (PARTNER_LOCATIONS.location_id)) AS Heures_Of_Operation FROM PARTNER_LOCATIONS O WH PARTNER_LOCATIONS .location_id = '3' "; $ resultat = mysqli_query ($ conn, $ sql); – ASH