本文共 794 字,大约阅读时间需要 2 分钟。
mochijson2:
编码 A = mochijson2:encode({struct, [{strKey, <<"strVal">>}, {intKey, 10}, {arrayKey, [1, 2, 3]}]}).
[123, [34,<<"abc">>,34],58,[34,<<"strVal">>,34],44,[34,<<"intKey">>,34],58,"10",44, [34,<<"arrayKey">>,34],58[91,"1",44,"2",44,"3",93],125]
123 <=> {
34 <=> \"
58 <=> :
44 <=> ,
125 <=> }
整数,浮点数,字符串解析为字符串,原子解析为二进制字符串
解码 mochijson2:decode(A){struct,[{<<"strKey">>,<<"strVal">>},{<<"intKey">>,10}, {<<"arrayKey">>,[1,2,3]}]}
解码的时候无论key是什么都会被解析为二进制字符串,而value则是原来的值
mochijson:
编码:A = mochijson:encode({struct, [{strKey, <<"strVal">>}, {intKey, 10}, {arrayKey, [1, 2, 3]}]}).
[123,"\"strKey\"",58,"\"strVal\"",44,"\"intKey\"",58,"10",44,"\"arrayKey\"",58,[34,"\\u0001","\\u0002","\\u0003",34],125]
解码:mochijson:decode(A).
{struct,[{"strKey","strVal"},{"intKey",10},{"arrayKey",[1,2,3]}]}
转载地址:http://qxxlf.baihongyu.com/