2017-04-25 44 views
-3

我一直試圖在iOS應用程序中解析這個JSON響應。但不幸的是我無法做到這一點。我嘗試了所有可以但仍然沒有運氣的方式。你能幫我解決這個問題嗎?如何在iOS應用程序中解析嵌套的JSON響應

「d_wtime」=「{'Sunday':''from'ours':'12','fromtype':'PM','tohours':'12','totype':'AM' fromhours2 ':' 12' , 'fromtype2': 'PM', 'tohours2': '12', 'totype2': 'AM'}, '星期一':{ 'fromhours': '12', 'fromtype':」 PM」, 'tohours': '12', 'totype': 'AM', 'fromhours2': '12', 'fromtype2': 'PM', 'tohours2': '12', 'totype2': 'AM' }, '星期二':{ 'fromhours': '12', 'fromtype': 'PM', 'tohours': '12', 'totype': 'AM', 'fromhours2': '12', 'fromtype2' : 'PM', 'tohours2': '12', 'totype2': 'AM'}, '星期三':{ 'fromhours': '12', 'fromtype': 'PM', 'tohours': '12' , 'totype': 'AM', 'fromhours2': '12', 'fromtype2': 'PM', 'tohours2': '12', 'totype2': 'AM'}, '星期四':{ 'fromhours' :'12' , 'fromtype': 'PM', 'tohours': '12', 'totype': 'AM', 'fromhours2': '12', 'fromtype2': 'PM', 'tohours2':」 12' , 'totype2': 'AM'}, '星期五':{ 'fromhours': '12', 'fromtype': 'PM', 'tohours': '12', 'totype': 'AM',」 fromhours2 ':' 12' , 'fromtype2': 'PM' , 'tohours2': '12', 'totype2': 'AM'}, '星期六':{ 'fromhours': '12', 'fromtype': 'PM', 'tohours': '12', 'totype' : 'AM', 'fromhours2': '12', 'fromtype2': 'AM', 'tohours2': '12', 'totype2': 'AM'}}「;

+0

更新您的問題與您嘗試解析此JSON和清楚地解釋您遇到的問題。 – rmaddy

+0

在上面顯示的回覆中。有幾個標籤。我需要在應用程序中顯示的輸出類似於beelow格式星期日 - 12 PM至12 AM 星期一 - 12 PM至12 AM 星期二 - 12 PM至12 AM 星期三 - 12 PM至12 AM 星期四 - 12 PM 12 AM 星期五下午12點到上午12點 星期六下午12點到上午12點 星期日下午12點到上午12點 –

+0

我需要使用4個標籤,它們是......「fromhours」,「fromtype」 ,「tohours」,「totype」 –

回答

0

應該像

let JSONArray = response["d_wtime"] as! [[String:[String: String]]] 
for JSONDic in JSONArray { 
    let sundayJSON = JSONDic["Sunday"] as! [String: String] 
    let fromHours = sundayJSON["fromhours"] as! String 
    . 
    . 
    . 
} 

,但我認爲JSON是醜陋的,你可以有一個更加動態和通用JSON

+0

非常感謝你的時間。我需要在實際上工作。我從你的評論中意識到,迴應是醜陋的。我會檢查我們的團隊成員,讓它更好,並繼續進行下去。 –