0

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

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

我想要类似 ["number","email","officeId"] 的“DART”

4

1 回答 1

1

如果你有这样的事情:

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)

让我知道这是否是你要找的。

于 2022-02-21T16:16:34.230 回答