我是Erlang的新手,我正在尝试将以下内容转换为dict
:
{struct,[{<<"1">>,<<"2,3,4">>},{<<"2">>,<<"2,3,4">>}]}
我使用mochijson2
解码后面的json后得到了这个:
<<"{"1":"2,3,4","2":"2,3,4"}">>
我正在寻找的最终结果将是:
1 -> [2,3,4]
2 -> [2,3,4]
我认为这是一个支持者,但不确定如何继续进行转换。感谢
答案 0 :(得分:0)
我不确定你要求的是什么,但可能是这样:
1> Term = {struct,[{<<"1">>,<<"2,3,4">>},{<<"2">>,<<"2,3,4">>}]}.
{struct,[{<<"1">>,<<"2,3,4">>},{<<"2">>,<<"2,3,4">>}]}
2> {struct, PropList} = Term.
{struct,[{<<"1">>,<<"2,3,4">>},{<<"2">>,<<"2,3,4">>}]}
3> Dict = dict:from_list(PropList).
{dict,2,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],
[[<<"2">>|<<"2,3,4">>]],
[],[],
[[<<"1">>|<<"2,3,"...>>]],
[]}}}
4> dict:fetch_keys(Dict).
[<<"2">>,<<"1">>]
5> dict:fetch(<<"1">>, Dict).
<<"2,3,4">>