【发布时间】:2012-03-13 19:48:17
【问题描述】:
我有两个对象,我想将它们捆绑在一起并以数组的形式发送,用 mochijson 编码为 JSON。它们是:
> Book0 = {struct, [{"title", "a book"}, {"id", "1"}]}.
> Book1 = {struct, [{"title", "another book"}, {"id", "2"}]}.
然而,
> mochijson:encode({struct, [{"books", [Book0, Book1]}]}).
** exception exit: {json_encode,{bad_char,{struct,[{"title","a book"},
{"id","1"}]}}}
in function mochijson:json_encode_string_unicode_1/1 (src/mochijson.erl, line 203)
in call from mochijson:json_encode_string_unicode/1 (src/mochijson.erl, line 190)
in call from mochijson:'-json_encode_proplist/2-fun-0-'/3 (src/mochijson.erl, line 151)
in call from lists:foldl/3 (lists.erl, line 1197)
in call from mochijson:json_encode_proplist/2 (src/mochijson.erl, line 154)
如何为 mochijson 构建我的数据?我知道article,但遗憾的是,它不包括对象数组。
【问题讨论】: