2017-04-25 42 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

非常感谢你的时间。我需要在实际上工作。我从你的评论中意识到,回应是丑陋的。我会检查我们的团队成员,让它更好,并继续进行下去。 –