我正在尝试从使用twiter api时检索的列表中提取一个hashtag。
我使用它来提取hashtag:
case extract(<<"entities">>, L) of
{found, {TE}} ->
{found, Hashtags} = extract(<<"hashtags">>, TE);
not_found -> Hashtags = hash_not_found
end,
extract(K, L) ->
case lists:keyfind(K, 1, L) of
{_, M} -> {found, M};
false -> not_found
end.这为我提供了一个格式为:
[{[{<<"text">>,<<"London">>},{<<"indices">>,[120,127]}]}]我只想从中提取标签,在本例中是伦敦。不过,每次提取tweet时,这个标签都会有所不同。任何想法或建议都值得感谢。
除非迫不得已,否则我不希望更改以前的代码。我更愿意学习如何从列表中提取我需要的东西。
发布于 2014-11-18 19:53:27
猜测一下extract函数是做什么的,应该是这样的:
case extract(<<"hashtags">>, TE) of
{found, Hashtags} ->
case extract(<<"text">>, Hashtags) of
{found, HashtagTexts} -> HashtagTexts;
not_found -> hash_not_found
end;
not_found -> hash_not_found
end另请参阅标准库中的proplists模块。
https://stackoverflow.com/questions/26993102
复制相似问题