ios - 打印所选部门 ID 的所有员工姓名?

标签 ios json swift

当我选择特定部门(名称)并使用该部门名称(获取其部门 ID)并使用该 ID 搜索所有员工数据或所有员工数据时,我使用此代码保存所有员工数据这类似于将部门 ID 保存到数组中并打印它。但是当我使用该代码时,它打印员工 ID nil 并打印所有员工姓名(对于所有部门 ID)

enter image description here

if let deptt = dictData["departments"] as? [Any] {

                print(deptt)

                for i in deptt as! [[String : Any]]
                {
                    let depttName = i["name"] as? String
                    let depttID = i["id"] as? String
                    //print(i["name"]!)

                    if depttName == selectedDeptt
                    {
                        let dd = depttID
                        print("dddd : \(dd)")

                        let emp = dictData["employees"] as? [Any]

                        for j in emp as! [[String : Any]]
                        {
                            let empID = j["department_id"] as? String
                            let empName = j["name"] as? String

                            print("Employee ID is : \(String(describing: empID))")

                            if depttID == empID
                            {
                                print("Employee ID is : \(String(describing: empID))")
                                print("Employee Names : \(String(describing: empName))")
                                arrEmp.append(empName!)
                            }
                        }
                    }
                }
            }
print(arrEmp)

最佳答案

我认为,您正在将部门 ID 与员工 ID 进行比较,这将不匹配。您应该获取员工的部门 ID,然后将该 ID 与选定的部门 ID 进行比较。

关于ios - 打印所选部门 ID 的所有员工姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49271510/

相关文章:

ios - UITextview-UIKeyboard关闭

php - 使用 PHP 从简单的 JSON 数组创建多维数组

javascript - 获取API并返回特定数据

iOS swift 3 : Share Data from share extension to Host App

ios - 请求完成处理程序 fatal error : unexpectedly found nil while unwrapping an optional value exception

ios - IBM Watson 语音转文本 : Not able to transcribe the text using the Swift SDK

iOS 7 UIWebView 不渲染

ios - 从 AppDelegate.m 加载 View (默认情况下的其他 View )

json - 在 AngularJS 中解析 JSON 字符串 - 给出未定义

ios - 如何知道选择了哪个部分? swift