我正在尝试解析以下JSON响应,以使用 SwiftyJSON 获取特定日期的时间和可用性。 我已成功解析以从 timeSlots 获取日期。
但是,我无法从响应中获得特定日期的“时间”。
{
"statusCode": 200,
"doctorDetailsList": null,
"doctorDetails": {
"id": 219,
"doctorName": "Doris Wunsch",
"qualification": "MD",
"consultationFee": 760,
"experience": 0,
"timeSlots": {
"06/07/2016": [
{
"date": 1465432200000,
"time": "6:00 AM",
"availability": true
},
{
"date": 1465452000000,
"time": "11:30 AM",
"availability": true
}
],
"06/08/2016": [
{
"date": 1465259400000,
"time": "6:00 AM",
"availability": true
},
{
"date": 1465279200000,
"time": "11:30 AM",
"availability": true
}
],
"06/09/2016": [
{
"date": 1465365600000,
"time": "11:30 AM",
"availability": true
}
]
}
},
"totalDoctors": 0,
"message": null
}
这是我为了获得 timeSlots 而采取的措施:
let todaysSlots = (self.doctorProfileDetail!["doctorDetails"]["timeSlots"].dictionary?.keys.sort()[0])!
作为回报,它正在给予“06/07/2016”。
如何获得时间和可用性?
答案 0 :(得分:0)
得到了结果:
let todaysDate = (self.doctorProfileDetail!["doctorDetails"]["timeSlots"]["06/07/2016"])[0]["time"]
let isAvailable = (self.doctorProfileDetail!["doctorDetails"]["timeSlots"]["06/07/2016"])[0]["availability"]
答案 1 :(得分:0)
var Data : NSMutableDictionary = NSMutableDictionary()
do {
let path: String = NSBundle.mainBundle().pathForResource("Swift", ofType: "json")!
let url: NSURL = NSURL.fileURLWithPath(path)
let req: NSURLRequest = NSURLRequest(URL: url)
let data: NSData = try NSURLConnection.sendSynchronousRequest(req, returningResponse: nil)
let json: [NSObject : AnyObject] = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! [NSObject : AnyObject]
Data = json["doctorDetails"]?.valueForKey("timeSlots") as! NSMutableDictionary
print(Data)
let time : NSMutableDictionary = Data.valueForKey("06/07/2016")?.objectAtIndex(1) as! NSMutableDictionary
let timestring = time.valueForKey("time") as! String
print(timestring)
let availability : NSMutableDictionary = Data.valueForKey("06/07/2016")?.objectAtIndex(1) as! NSMutableDictionary
let numberbool = availability.valueForKey("availability") as! Bool
print(numberbool)
您可以使用此代码并获得时间和可用性享受