简体   繁体   中英

concatenating string with variable in erlang

I have below string in erlang which I get from Msg#archive_message.body

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

I need to make it

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

and pass into a function. any help is appreciated.

If

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

is a string you just need to convert it to binary with erlang:list_to_binary/1

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

Then you can use jsx to parse it into a list

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

Or into a map

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM