erlang中修改list里面tuple—list的值的类型
有个这样的例子:list里面是多个个tuple—list 或者maps,
ListA = [[{},{}}],[{},{}]], 举例:
A = [[{<<"CARDISSUERID">>,<<"2">>}, {<<"CARDSTOCKTYPE">>,1}, {<<"CARDTYPE">>,0}, {<<"DERIVATIVESPRODUCTTYPE">>,1}, {<<"PARAM_VER">>,<<"195">>}, {<<"PREASSIGNMENTATTRIBUTE">>,1}, {<<"PRODUCTTYPE">>,9800}, {<<"SALEVALUE">>,<<"0">>}], [{<<"CARDISSUERID">>,<<"2">>}, {<<"CARDSTOCKTYPE">>,1}, {<<"CARDTYPE">>,0}, {<<"DERIVATIVESPRODUCTTYPE">>,1}, {<<"PARAM_VER">>,<<"195">>}, {<<"PREASSIGNMENTATTRIBUTE">>,1}, {<<"PRODUCTTYPE">>,9800}, {<<"SALEVALUE">>,<<"0">>}]].
想把 key是 <<"CARDISSUERID">> 的 值的类型,改成integer ,目前是 binary ,{<<"CARDISSUERID">>,<<"2">>}
直接上代码,修改对应key的值,直接干:
[lists:map(fun(X) -> if element(1,X) == <<"CARDISSUERID">> -> {element(1,X), binary_to_integer(element(2,X))}; true -> X end end,Z)|| Z<-A].
执行结果如下: