【发布时间】:2015-12-08 23:43:14
【问题描述】:
我有“困难”的道具列表。我需要到达 serviceCatalog 并遍历它的所有值,直到我得到一个 name=me
J =[{<<"access">>,
{[{<<"token">>,
{[{<<"issued_at">>,<<"2015-09-12T13:27:38.789879">>},
{<<"expires">>,<<"2015-09-12T14:27:38Z">>},
{<<"id">>,<<"fe">>},
{<<"tenant">>,
{[{<<"description">>,null},
{<<"enabled">>,true},
{<<"id">>,<<"01">>},
{<<"name">>,<<"service">>}]}},
{<<"audit_ids">>,[<<"f">>]}]}},
{<<"serviceCatalog">>,
[{[{<<"endpoints">>,
[{[{<<"adminURL">>,<<"http://8.198.99.999:8080">>},
{<<"region">>,<<"RegionOne">>},
{<<"internalURL">>,
<<"http://8.198.99.999:8080/v1/AUTH_01a"...>>},
{<<"id">>,<<"30">>},
{<<"publicURL">>,<<"8.198.99.999:8080/v1/"...>>}]}]},
{<<"endpoints_links">>,[]},
{<<"type">>,<<"object-store">>},
{<<"name">>,<<"my">>}]},
{[{<<"endpoints">>,
[{[{<<"adminURL">>,<<"8.198.99.999:8080/v2.0">>},
{<<"region">>,<<"RegionOne">>},
{<<"internalURL">>,<<"8.198.99.999:8080/v2.0">>},
{<<"id">>,<<"4b3f44a5c64b4bd8b10c376c858b"...>>},
{<<"publicURL">>,<<"8.198.99.999:8080"...>>}]}]},
{<<"endpoints_links">>,[]},
{<<"type">>,<<"identity">>},
{<<"name">>,<<"other">>}]}]},
{<<"user">>,
{[{<<"username">>,<<"my">>},
{<<"roles_links">>,[]},
{<<"id">>,<<"8">>},
{<<"roles">>,[{[{<<"name">>,<<"admin">>}]}]},
{<<"name">>,<<"me">>}]}},
{<<"metadata">>,
{[{<<"is_admin">>,0},
{<<"roles">>,
[<<"e">>]}]}}]}}]
我正在寻找这样做的好方法。 我开始了这样的实现(但看起来有更优雅的解决方案):
A1=proplists:get_value(<<"access">>,J).
A=element(1,A1).
B=proplists:get_value(<<"token">>, A).
C=element(1,B).
D=proplists:get_value(<<"serviceCatalog">>, C).
欢迎提出建议
【问题讨论】:
-
请说明问题;你是说你想用一个键
<<"serviceCatalog">>来查找这个数据中的所有元组,它的值在其中的某个位置包含一个值为{<<"name">>, <<"me">>}的元组,如果{<<"name">>, <<"me">>}是,你是否希望返回整个<<"serviceCatalog">>元组成立?顺便说一句,如果这是您想要的,请注意您的示例数据不匹配,因为{<<"name">>, <<"me">>}仅存在于{<<"user">>, ...}元组中。