1

我是 Erlang 的新手,正在尝试将以下内容转换为dict

{struct,[{<<"1">>,<<"2,3,4">>},{<<"2">>,<<"2,3,4">>}]}

在使用以下 json 解码后,我得到了这个mochijson2

<<"{"1":"2,3,4","2":"2,3,4"}">>

我正在寻找的最终结果将类似于:

1 -> [2,3,4]
2 -> [2,3,4]

我认为这是一个 proplist,但不确定如何进行转换。谢谢

4

1 回答 1

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">>
于 2013-08-14T20:57:11.497 回答