4

我需要使用 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"]}
4

1 回答 1

3

其实这里就是

mochijson2:encode({
            struct,[
                {topic, list_to_binary(Topic)},
                {messages, [list_to_binary(M) || M <- List]}
            ]
        })
于 2010-07-20T20:41:19.610 回答