使用mochiweb对列表进行JSON编码

时间:2010-07-20 20:33:54

标签: json erlang mochiweb

我需要使用mochiweb对列表进行JSON编码。

如何获得以下内容:

List = ["This is message 1.", "This is message 2.", "This is the last message"]
mochijson2:encode({struct,[{messages,list_to_binary(List)}]

生成这一点JSON:

{"messages":"["This is message 1.","This is message 2.","This is the last message"]}

1 个答案:

答案 0 :(得分:3)

实际上,这是

mochijson2:encode({
            struct,[
                {topic, list_to_binary(Topic)},
                {messages, [list_to_binary(M) || M <- List]}
            ]
        })