如何通过键包含点访问groovy中的地图值? [英] How to access map values in groovy by key containing dot?
本文介绍了如何通过键包含点访问groovy中的地图值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的地图:
data = {user.name:John,
user。姓氏:Doe,
city:NY}
我可以访问attiribute'城市这样:
data.city
是否有类似的访问user.name属性的方法?
解决方案
假设你的意思是:
data = ['user.name':John,'user.surname':Doe ,city:NY]
(方形大括号为地图定义,关键名字),我相信
data.'user.name'
/ pre>
应该这样做
I have map like this:
data = {user.name: "John", user.surname: "Doe", city: "NY"}
I can access attiribute 'city' this way:
data.city
Is there is a similar way to access 'user.name' attribute?
解决方案Assuming you meant:
data = [ 'user.name':"John", 'user.surname':"Doe", city:"NY" ]
(square braces for the map definition, and quotes round the dotted key names), I believe that
data.'user.name'
should do it
这篇关于如何通过键包含点访问groovy中的地图值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文