使用对象数组渲染json

时间:2013-12-07 12:14:14

标签: json mongodb erlang chicagoboss

我有这样的代码:

index('GET', []) ->
    Users = boss_db:find(consumer, []),
    {json, [{"users", Users}]}.

我有一个错误:

{function_clause,
    [{boss_json,json_data1,
         [[{consumer,"consumer-52a3024b4346e12118000001",<<"qwe">>,
               <<"qwe">>},
           {consumer,"consumer-52a302c84346e12118000002",<<"asd">>,
               <<"asd">>},
           {consumer,"consumer-52a305264346e12118000003",<<"zxc">>,
               <<"zxc">>}],
          ["user"],
          []],
         [{file,"src/boss/boss_json.erl"},{line,23}]}

问题出在哪里?怎么解决?

1 个答案:

答案 0 :(得分:1)

可能是最后一行的错误,用户必须是原子,而不是字符串:

 {json, [{users, Users}]}.