返回Groovy中的嵌套密钥 [英] Return Nested Key in Groovy

查看:106
本文介绍了返回Groovy中的嵌套密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确定使用groovy返回嵌套键值的最佳方式。如果我有一张地图:

I am trying to determine the best way to return nested key values using groovy. If I have a map:

def map = [
   OrganizationName: 'SampleTest',
   Address: [
      Street: '123 Sample St',
      PostalCode: '00000',
   ]
]

有没有办法返回所有的键? OrganizationName OrganizationURL Address.Street Address.PostalCode ?如果地图中没有地图,我可以使用map.keySet()作为String []。我应该只是循环每个键,看看它是否是另一个地图的一个实例?

Is there a way to return all of the keys? OrganizationName, OrganizationURL, Address.Street, Address.PostalCode? If I didn't have an map within a map I could use map.keySet() as String[]. Should I just loop through each key and see if it is an instanceof another map?

推荐答案

没有这样的方法在groovy。您需要使用 instanceof 并可能是递归方法。

There's no such method You're looking for in groovy. You need to do it using instanceof and probably a recursive method.

这篇关于返回Groovy中的嵌套密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆