在Erlang中操作复杂列表

在Erlang中操作复杂列表,erlang,ejabberd,Erlang,Ejabberd,我在Erlang有这个列表 [{title, "ad"}, {description, "fdf"}, {allow_change_subj, true}, {allow_query_users, true}, {allow_private_messages, true}, {allow_private_messages_from_visitors, anyone}, {allow_visitor_status, true}, {allow_visitor

我在Erlang有这个列表

[{title,
"ad"},
{description,
"fdf"},
{allow_change_subj,
true},
{allow_query_users,
true},
{allow_private_messages,
true},
{allow_private_messages_from_visitors,
anyone},
{allow_visitor_status,
true},
{allow_visitor_nickchange,
true},
{public,
true},
{public_list,
true},
{persistent,
true},
{moderated,
true},
{members_by_default,
true},
{members_only,
false},
{allow_user_invites,
true},
{password_protected,
false},
{captcha_protected,
false},
{password,
[]},
{anonymous,
true},
{logging,
false},
{max_users,
200},
{allow_voice_requests,
true},
{voice_request_min_interval,
1800},
[{captcha_whitelist, []}, 
{affiliations, [{{"test1", "serverdomain.com", []},{owner,[]}}]}, {{"testuser4_gmail.com", "serverdomain.com", []},    {member, []}}],
{subject,
[]},
{subject_author,
[]}]]
我正在尝试获取关键“从属关系”下的用户名(test1,testuser4_gmail.com),但从该列表中获取用户名时遇到问题

在此方面的任何帮助都将不胜感激

更新:

我很好地得到了'宣誓'的关键和它下的一切,但在我所寻找的问题。我提供一个例子

 ->   Listt = [{captcha_whitelist, []}, {affiliations, [{{"test1", "54.69.16.10", []},{owner,[]}}]}].
    
  ->  lists:keyfind('affiliations',1, Listt).
  Output : {affiliations,[{{"test1","54.69.16.10",[]},{owner,[]}}]}

Target:获取诸如“test1”之类的值,以及更多(如果有的话)诸如“test1”、“testuser4\u gmail.com”

根据您的代码示例,下面是一些可以进一步提取的方法

以下是您的代码示例结构:

1> Listt = [{captcha_whitelist, []}, {affiliations, [{{"test1", "54.69.16.10", []},{owner,[]}}]}].
[{captcha_whitelist,[]},
 {affiliations,[{{"test1","54.69.16.10",[]},{owner,[]}}]}]
3> Users = lists:map(fun({User, Role}) -> User end, Affiliations).
[{"test1","54.69.16.10",[]}]
我将使用PropList提取第一级:

2> Affiliations =  proplists:get_value(affiliations,Listt).
[{{"test1","54.69.16.10",[]},{owner,[]}}]
列表:映射/2
和模式匹配可以帮助您仅使用结构的第一部分转换列表:

1> Listt = [{captcha_whitelist, []}, {affiliations, [{{"test1", "54.69.16.10", []},{owner,[]}}]}].
[{captcha_whitelist,[]},
 {affiliations,[{{"test1","54.69.16.10",[]},{owner,[]}}]}]
3> Users = lists:map(fun({User, Role}) -> User end, Affiliations).
[{"test1","54.69.16.10",[]}]
如果要进一步提取,可以执行以下操作:

4> lists:map(fun({Username, Server, _}) -> Username end, User). 
["test1"]
或者,您甚至可以同时执行步骤3和步骤4,并获得用户列表:

5> lists:map(fun({{User, Server, _}, Role}) -> User end, Affiliations).       
["test1"]

也许你应该展示一下你第一次尝试的代码?我只是想了解你的合作关系,但不知道如何前进。我提供它作为有问题的更新。有什么问题吗?输出看起来是正确的,好像你们并没有读过这个问题,只是更新了一下