2
我在erlang中有一个列表,我需要将其转换为查询字符串参数并通过http发送。通过http发送没有问题,但querystring参数没有按照我想要的格式进行格式化。我想两件事情:将列表转换并格式化为erlang中的字符串
片段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'
片段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'
有人可以帮助我在我可以接受的所有项目的方式转换和格式化列表在列表中用'/'分隔
在此先感谢
请注意'list:join/2'只在最近的19.x中添加。在这种情况下,可以在早期版本中使用'string:join/2'。 –
@ DerekBrown:好点 - 我编辑了这个帖子来记下这一点。 –