在erlang中将字符串与变量连接起来

concatenating string with variable in erlang

我在 erlang 中有以下字符串,我从 Msg#archive_message.body

{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}

我需要做到

  <<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>

并传递给一个函数。感谢您的帮助。

如果

{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}

是一个字符串,你只需要用erlang把它转换成二进制:list_to_binary/1

Eshell V6.2  (abort with ^G)
1> unicode:characters_to_binary("{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}").
<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>

然后可以用jsx解析成列表

2> jsx:decode(<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>).
[{<<"message">>,<<"tttfdfdfdfdddtt">>},
 {<<"customid">>,<<"454dddfdfdfd">>}]

或成地图

3> jsx:decode(<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>, [return_maps]).
#{<<"customid">> => <<"454dddfdfdfd">>,
  <<"message">> => <<"tttfdfdfdfdddtt">>}