2017-06-25 50 views
-3

我正在從JSON以下響應解析這樣的後: Please click the image如何獲取valueForKey?

Array s: { 
    endTimeAm = ""; 
    endTimePm = "22:00"; 
    operatingDay = Sun; 
    startTimeAm = "07:00"; 
    startTimePm = ""; 
} 

請讓我知道如何從下面得到「operatingDay」的價值?

print("Array s: \(cashPointOperatingDays[0])") 
     guard let firstDict = cashPointOperatingDays[0] as? [[String: String]] else { 
      return 
     } 
     print("First Dictionary: \(firstDict["operatingDay"])") //error showing line 
    } 

但我正在逐漸

無法下標類型的值 '[[字符串:字符串]]' 與類型的索引 '字符串'」錯誤

回答

0

您的陣列其實不是數組而是字典。

print("JSON object s: \(cashPointOperatingDays[0])") 
     guard let firstDict = cashPointOperatingDays[0] as? [String: String] else { 
      return 
     } 
     print("First Dictionary: \(firstDict["operatingDay"])") //error showing line 
+0

那麼請告訴我該怎麼辦? –

+0

再看看我的a nswer – user3441734

+0

https://stackoverflow.com/questions/44743257/how-to-use-alamofire-with-object-mapper-in-swift3-to-map-an-array-inside-an-arra –