List 将列表转换并格式化为erlang中的字符串

List 将列表转换并格式化为erlang中的字符串,list,erlang,List,Erlang,我在erlang中有一个列表,需要将其转换为querystring参数并通过http发送。通过http发送没有问题,但是querystring参数的格式不是我想要的。我尝试了两件事: 片段1 error_logger:info_msg("~p", [Mylist]), %% ==> prints [<<"foo">>,<<"bar">>] Response = httpc:request("http://someserver/someac

我在erlang中有一个列表,需要将其转换为querystring参数并通过http发送。通过http发送没有问题,但是querystring参数的格式不是我想要的。我尝试了两件事:

片段1

error_logger:info_msg("~p", [Mylist]),  %% ==> prints [<<"foo">>,<<"bar">>] 
Response = httpc:request("http://someserver/someaction?mylist=" ++ [Mylist]). 
%% ==> Server receives Mylist param as: 'foobar' but I want it to be 'foo/bar'
error\u logger:info\u msg(“~p”,[Mylist]),%%==>打印[,]
响应=httpc:请求(“http://someserver/someaction?mylist=“++[Mylist])。
%%==>服务器接收Mylist参数为:“foobar”,但我希望它是“foo/bar”
片段2

error_logger:info_msg("~p", [Mylist]),  %% ==> prints [<<"foo">>,<<"bar">>] 
IOList = io_lib:format("~p", [Mylist]),
FlatList = lists:flatten([IOList]),
Response = httpc:request("http://someserver/someaction?mylist=" ++ [FlatList]).
%% ==> Server receives Mylist param as: '[<<"foo">>,<<"bar">>]' but I want it to be 'foo/bar'
error\u logger:info\u msg(“~p”,[Mylist]),%%==>打印[,]
IOList=io_lib:format(“~p”,[Mylist]),
FlatList=列表:展平([IOList]),
响应=httpc:请求(“http://someserver/someaction?mylist=“++[FlatList])。
%%==>服务器以“[,]”的形式接收Mylist参数,但我希望它是“foo/bar”
是否有人能帮助我转换和格式化列表,以便我可以接收列表中以“/”字符分隔的所有项目


提前感谢

如果您希望在URL中的列表元素之间显示一个
/
字符,则必须将其放在那里。一种方法是:

这将导致一个由字符串和二进制文件组成的iolist作为URL参数传递给
httpc:request/1
,在我尝试时它对我起作用,但严格来说是不正确的,因为URL类型是字符串。要实现这一点,您可以首先在
Mylist
中转换二进制文件,并展平连接的结果以获得字符串:

Value = lists:flatten(lists:join("/", [binary_to_list(B) || B <- Mylist])),
Response = httpc:request("http://someserver/someaction?mylist=" ++ Value).

Value=lists:flatten(lists:join(“/”),[binary_to_list(B)| | B如果希望在URL中的列表元素之间显示
/
字符,则必须将其放在那里。一种方法是:

这将导致一个由字符串和二进制文件组成的iolist作为URL参数传递给
httpc:request/1
,在我尝试它时,它对我有效,但严格来说是不正确的,因为URL类型是字符串。要实现这一点,您可以首先在
Mylist
中转换二进制文件,并展平连接的结果以获得字符串:

Value = lists:flatten(lists:join("/", [binary_to_list(B) || B <- Mylist])),
Response = httpc:request("http://someserver/someaction?mylist=" ++ Value).

Value=lists:flant(lists:join(“/”,[binary_to_list(B)| | B注意,
lists:join/2
仅在最近的19.x中添加。对于早期版本,在本例中可以使用
string:join/2
。注意
lists:join/2
仅在最近的19.x中添加。对于早期版本,在本例中可以使用
string:join/2