【发布时间】:2018-07-08 05:04:25
【问题描述】:
所以,我有从通知中获得的 userInfo 数据,我想解码这些数据并将其传递给另一个类。我将 swiftyJSON 用于 json 解码器。这是我的代码:
func decodedNotificationTransactionData(data: Any, completionHandler: @escaping (_ dict: [String : Any]) -> ()){
let dict = JSON(data)
print ("this is json data \(dict)")
print("this is status \(dict["status"])")
let test = [
"id" : "\(dict["id"])",
"orderDate" : "\(dict["orderDate"])",
"patientName" : "\(dict["patient"]["fullName"])",
"patientAddress" : "\(dict["patient"]["address"])",
"caregiverName" : "\(dict["care"]["fullName"])",
"caregiverAddress" : "\(dict["care"]["address"])",
"serviceType" : "\(dict["service"]["label"])",
"status" : "\(dict["status"])",
"price" : "\(dict["totalAmount"])",
"otherNote" : "\(dict["otherNote"])",
"totalService" : dict["detailDatas"].count,
"serviceLongType" : dict["detailDatas"][0]["type"],
"jsonContent" : dict
] as [String : Any]
completionHandler(test)
}
this the "print ("this is json data (dict)")" result
当代码到达 print("this is json data (dict)") 数据是没有问题的,但是当代码到达 print("this is status (dict[ "status"])") 它在日志上给出 null。您是否遇到过同样的问题?
【问题讨论】:
标签: ios json swift decode swifty-json