2017-10-10 43 views
-2

我有一個小時的操作json。在那是一個小時的列表。我想列表是一個數組,我通過索引作爲對象。如何從ns字典的數組中創建nsarray?

"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

說些什麼,而不是僅僅反對投票.. – 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

回答

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 

您可以使用ComponentSeparatedByString獲得期望的結果。您甚至需要根據您的要求修改此代碼。

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

大家好..我使用的Objective - C – ASH

+0

Nupur - 我怎樣才能改變JSON結果。當它從下面的到來。 – ASH

+0

$ SQL = 「SELECT * PARTNER_LOCATIONS(SELECT GROUP_CONCAT(CONCAT(」{\星期幾\ 「:\ '」',LOCATIONS_BUSINESS_HOURS.dayofweek, '\ 「\ 」OPEN_TIME \「:\」',LOCATIONS_BUSINESS_HOURS.open_time, '\「,\」close_time \「:\」',LOCATIONS_BUSINESS_HOURS.close_time,'\「}'))FROM LOCATIONS_BUSINESS_HOURS WHERE LOCATIONS_BUSINESS_HOURS.location_id ='3'GROUP BY(PARTNER_LOCATIONS.location_id))AS Hours_Of_Operation FROM PARTNER_LOCATIONS WHERE PARTNER_LOCATIONS .location_id ='3'「; $ result = mysqli_query($ conn,$ sql); – ASH