开发者

How to access map values in groovy by key containing dot?

开发者 https://www.devze.com 2023-02-28 03:01 出处:网络
I have map like this: data = 开发者_高级运维{user.name: \"John\", user.surname: \"Doe\", city: \"NY\"}

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

0

精彩评论

暂无评论...
验证码 换一张
取 消