打印键值在 map<String,dynamic> Employee 中为 null

Print keys were values is null in map<String,dynamic> Employee in dart

这是代码 json 我想从中获取所有键的代码,如果值为 null

{
   "service": "register",
   "employee": {
       "employeeId": "bcvfevse",
       "officeId": null,
       "email": null,
       "name" : "Chetan Patil",
       "position" : "Flutter Developer",
       "number" : null
   },
   "device": {
       "type": "android",
       "uniqueId": "9774d56d682e549c"
   }
}

我想要 “DART”

中这样的 ["number","email","officeId"]

如果你有这样的事情:

var json = {
   "service": "register",
   "employee": {
       "employeeId": "bcvfevse",
       "officeId": null,
       "email": null,
       "name" : "Chetan Patil",
       "position" : "Flutter Developer",
       "number" : null
   },
   "device": {
       "type": "android",
       "uniqueId": "9774d56d682e549c"
   }

在 Dart 中,您可以执行以下操作:

var nullEntries = (json['employee'] as Map<String, dynamic>).entries.where((e) => e.value == null).toList();

那么如果你这样打印出来:

print(nullEntries.map((p) => p.key));

你得到:

(officeId, email, number)

如果这就是您要找的,请告诉我。