mochiweb 、mochijson
2016-05-23 17:21
501 查看
Mochiweb是Erlang实现的一个开源Web服务器,它设计的一个亮点就是他本身的Http请求的参数化模型。因此我们可以用OO的方式来理解它的相关用法。
它的实现在mochiweb_request模块.在mochiweb中,每个client请求其构造一个 Req 对象(注:这个“对象“只是便于理解的提法), Req 可以理解成 mochiweb_request 的一个参数化或实例化.
http://www.360doc.com/content/12/1003/15/10834595_239290379.shtml http://blog.csdn.net/dp0304/article/details/6994435
mochijson2 :The mochijson2 API essentially consists of just two functions, which (if you've downloaded mochiweb) can be used directly from the Erlang shell as follows:
http://stackoverflow.com/questions/1000046/mochijson2-examples
部分说明
%% @author Bob Ippolito <bob@mochimedia.com>
%% @copyright 2007 Mochi Media, Inc.
%% @doc Yet another JSON (RFC 4627) library for Erlang. mochijson2 works
%% with binaries as strings, arrays as lists (without an {array, _})
%% wrapper and it only knows how to decode UTF-8 (and ASCII).
%%
%% JSON terms are decoded as follows (javascript -> erlang):
%% <ul>
%% <li>{"key": "value"} ->
%% {struct, [{<<"key">>, <<"value">>}]}</li>
%% <li>["array", 123, 12.34, true, false, null] ->
%% [<<"array">>, 123, 12.34, true, false, null]
%% </li>
%% </ul>
%% <ul>
%% <li>Strings in JSON decode to UTF-8 binaries in Erlang</li>
%% <li>Objects decode to {struct, PropList}</li>
%% <li>Numbers decode to integer or float</li>
%% <li>true, false, null decode to their respective terms.</li>
%% </ul>
%% The encoder will accept the same format that the decoder will produce,
%% but will also allow additional cases for leniency:
%% <ul>
%% <li>atoms other than true, false, null will be considered UTF-8
%% strings (even as a proplist key)
%% </li>
%% <li>{json, IoList} will insert IoList directly into the output
%% with no validation
%% </li>
%% <li>{array, Array} will be encoded as Array
%% (legacy mochijson style)
%% </li>
%% <li>A non-empty raw proplist will be encoded as an object as long
%% as the first pair does not have an atom key of json, struct,
%% or array
%% </li>
%% </ul>
它的实现在mochiweb_request模块.在mochiweb中,每个client请求其构造一个 Req 对象(注:这个“对象“只是便于理解的提法), Req 可以理解成 mochiweb_request 的一个参数化或实例化.
http://www.360doc.com/content/12/1003/15/10834595_239290379.shtml http://blog.csdn.net/dp0304/article/details/6994435
mochijson2 :The mochijson2 API essentially consists of just two functions, which (if you've downloaded mochiweb) can be used directly from the Erlang shell as follows:
erl -pa path/to/mochiweb/ebin ... 1> mochijson2:decode(<<"[1,2,3]">>). [1,2,3] 2> iolist_to_binary(mochijson2:encode([1,2,3])). <<"[1,2,3]">>
ERL :: {struct, [{strKey, <<"strVal">>}, {intKey, 10}, {arrayKey, [1, 2, 3]}]} JSON :: {strKey:"strVal", intKey:10, arrayKey:[1, 2, 3]}
http://stackoverflow.com/questions/1000046/mochijson2-examples
部分说明
%% @author Bob Ippolito <bob@mochimedia.com>
%% @copyright 2007 Mochi Media, Inc.
%% @doc Yet another JSON (RFC 4627) library for Erlang. mochijson2 works
%% with binaries as strings, arrays as lists (without an {array, _})
%% wrapper and it only knows how to decode UTF-8 (and ASCII).
%%
%% JSON terms are decoded as follows (javascript -> erlang):
%% <ul>
%% <li>{"key": "value"} ->
%% {struct, [{<<"key">>, <<"value">>}]}</li>
%% <li>["array", 123, 12.34, true, false, null] ->
%% [<<"array">>, 123, 12.34, true, false, null]
%% </li>
%% </ul>
%% <ul>
%% <li>Strings in JSON decode to UTF-8 binaries in Erlang</li>
%% <li>Objects decode to {struct, PropList}</li>
%% <li>Numbers decode to integer or float</li>
%% <li>true, false, null decode to their respective terms.</li>
%% </ul>
%% The encoder will accept the same format that the decoder will produce,
%% but will also allow additional cases for leniency:
%% <ul>
%% <li>atoms other than true, false, null will be considered UTF-8
%% strings (even as a proplist key)
%% </li>
%% <li>{json, IoList} will insert IoList directly into the output
%% with no validation
%% </li>
%% <li>{array, Array} will be encoded as Array
%% (legacy mochijson style)
%% </li>
%% <li>A non-empty raw proplist will be encoded as an object as long
%% as the first pair does not have an atom key of json, struct,
%% or array
%% </li>
%% </ul>
相关文章推荐
- JavaScript实现复制或剪切内容到剪贴板功能的方法
- js 计算精度问题
- JavaScript 跨域访问的问题和解决过程
- 详解JavaScript中|单竖杠运算符的使用方法
- js实现放大缩小页面
- json解析中 opt和get的区别
- bzoj 4466 : [Jsoi2013]超立方体
- 使用bookshelf.js进行left join操作
- JSP
- javascript类学习(二)——类的私有变量、私有方法、共有变量、共有方法
- 关于Chrome调试中.min.js.map 404的问题
- JSON.stringify()、,JSON.eval(),JSON.parse()各自的区别于作用
- js提示确认删除吗
- Javascript的this用法
- js获取url参数,操作url参数
- 使用JavaScript进行进制转换将字符串转换为十进制
- javascript类学习(一)——构造器与原型链实现简单的继承
- json解析总结
- js 自定义弹出框
- JS实现字体逐个显示