Closed Ndeh-007 closed 1 year ago
Erlang's string type is just an alias of "list of integers", and jsone encodes strings as integer lists. To produce JSON strings, you need to pass binaries to the encoding function as follows:
%% strings (i.e., integer lists) are encoded as JSON arrays of integers
1> jsone:encode("hello").
<<"[104,101,108,108,111]">>
%% binaries are encoded as JSON strings
2> jsone:encode(<<"hello">>).
<<"\"hello\"">>
3> jsone:encode(list_to_binary("hello")).
<<"\"hello\"">>
It works beautifully. thank you very much.
Hello, I could use some help.
I am trying to encode some data in Erlang but I am having trouble getting the patterns down.
Here's the pre encoding section section of my code
Viewing in the browser, I get my output fine except for the
msg
whose value comes as an array of numbersPlease what changes am i to make such that i get a string instead of an array of numbers for the
msg
key?