python xml json库读取中文出错

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 53-56: ordinal not in range(128)

解决方法:xml库,添加如下

vi /usr/lib/python2.7/xml/etree/ElementTree.py

import sys
reload(sys)
sys.setdefaultencoding( “utf-8” )

 

dump json文件:

json.dumps(data, ensure_ascii=False, sort_keys=True, indent=4, separators=(‘,’, ‘: ‘)).replace(“\n”,”n”)

Erlang 安装使用rfc4627

环境: Ubuntu 14.04

编译

git clone git://github.com/tonyg/erlang-rfc4627.git

cd erlang-rfc4627/

make all

获取erlang library路径

jerry@iZ28ktvewfwZ:~$ erl
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:10] [kernel-poll:false]

Eshell V5.10.4 (abort with ^G)
1> code:get_path().
[“.”,”/usr/lib/erlang/lib/kernel-2.16.4/ebin”,
“/usr/lib/erlang/lib/stdlib-1.19.4/ebin”,
“/usr/lib/erlang/lib/xmerl-1.3.5/ebin”,
“/usr/lib/erlang/lib/wx-1.1.1”,
[…]|…]
2>

将文件夹拷贝到相应目录下

sudo cp -R erlang-rfc4627/ /usr/lib/erlang/lib/

 
测试使用

jerry@iZ28ktvewfwZ:~$ erl
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:10] [kernel-poll:false]

Eshell V5.10.4 (abort with ^G)
1> O = rfc4627:encode({obj, [{name, hideto}, {age, 23}]}).
“{\”name\”:\”hideto\”,\”age\”:23}”
2>