undefined function maps:to_json/1

 ̄綄美尐妖づ 提交于 2020-01-23 05:12:45

问题


This is one of the things I learned from Programming Erlang, 2nd Ed, but doesn't seem to work on shell

$ erl
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V6.2  (abort with ^G)
1> Dic = #{b => 1, a => 2}.
#{a => 2,b => 1}
2> maps:to_json(Dic).
** exception error: undefined function maps:to_json/1
3> 

What's wrong here?


回答1:


Programming Erlang, 2nd Ed was written before maps were introduced in release 17 (as experimental feature) and it seems that author of book, Joe Armstrong was too optimistic about them. Still some of proposed functionality and syntax is not yet implemented (or never will be).

Luckily, there are JSON parsers for erlang which support maps, check:

  • jiffy
  • jsx


来源:https://stackoverflow.com/questions/27803001/undefined-function-mapsto-json-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!