如何从NSDictionary swift 4获取关键数据

时间:2019-05-11 07:36:38

标签: swift nsdictionary

我想从NSDictionary获取结果,现在我想从Webservice获取此NSDictionary

我需要这个用语“您的请求未成功。请”

我尝试了此let ft = resultsm.value(forKeyPath: "Body.QR_FundTransferResponse.QR_FundTransferResult") as! String,但是它存储数据并为所有请求打印相同的值

let result:NSDictionary = dict! as NSDictionary 

The output is : 

  Body =     {
    "QR_FundTransferResponse" =         {
        "QR_FundTransferResult" = "Your request is unsuccessfull. 
       Please ";
          };
    };

1 个答案:

答案 0 :(得分:0)

假设您已在函数中使用此函数,并且结果为[String: Any]类型(例如字典):

guard let body = result["body"] as? [String: Any] else {
    // Failed to find body, return empty string
    return ""
}
guard let response = body["QR_FundTransferResponse"] as? [String: Any] else {
    return ""
}
guard let result = response["QR_FundTransferResult"] as? String else {
    return ""
}
// Now have "Your request is unsuccessful. Please "
return result

建议您检出Codable