Closed gemSender closed 10 years ago
why did you use binary_to_existing_atom rather than binary_to_atom
This is a documented behavior. Here's a relevant quote from README.md:
Erlson uses Erlang built-in binary_to_existing_atom/1 function for converting JSON field names into Erlang atoms. This is to prevent the VM from running out of atom space on malicious JSON input.
Generally, everything should just work out of the box in compiled projects. However, if you are using Erlson from Erlang shell, not all of your modules and correspondent atoms may be loaded. In this case, JSON field names for unknown atoms will be represented as binaries after parsing. To fix that, you can load all the necessary modules. This can be done, for example, by running this command:
Modules = [application:get_key(A, modules) || A <- application:loaded_applications()],
[ code:load(M) || lists:append(Modules) ].
Got it,thank you!
erlson:from_json( <<"{\"buildingType\":\"goldCollector\",\"buildingId\":1,\"result\":null}">>). the return value is [{buildingType,<<"goldCollector">>},{result,undefined}, {<<"buildingId">>,1}]. It should be [{buildingType,<<"goldCollector">>},{result,undefined}, {buildingId,1}].