APIJSON/README.md

300 lines
27 KiB
Markdown
Raw Normal View History

2016-11-24 23:36:31 +08:00
# APIJSON
2016-11-25 01:07:32 +08:00
2017-01-26 12:03:09 +08:00
[English Document](https://github.com/TommyLemon/APIJSON/blob/master/README(English).md)
2016-11-26 17:39:55 +08:00
2017-01-26 12:00:03 +08:00
APIJSON是一种JSON传输结构协议。<br />
2016-11-24 22:54:11 +08:00
2017-01-26 12:00:03 +08:00
客户端可以定义任何JSON结构去向服务端发起请求服务端就会返回对应结构的JSON字符串所求即所得。<br />
一次请求任意结构任意数据,方便灵活,不需要专门接口或多次请求。<br />
2017-03-05 23:07:38 +08:00
支持增删改查、模糊搜索、远程函数调用等。还能去除重复数据,节省流量提高速度!<br />
2016-12-09 22:09:37 +08:00
2017-01-26 12:00:03 +08:00
从此HTTP传输JSON数据没有接口更不需要文档<br />
客户端再也不用和服务端沟通接口或文档问题了!再也不会被文档各种错误坑了!<br />
服务端再也不用为了兼容旧版客户端写新版接口和文档了!再也不会被客户端随时随地没完没了地烦了!
2016-12-09 22:09:37 +08:00
2017-03-04 20:18:02 +08:00
举个栗子(查询类似微信朋友圈动态列表):
2016-11-24 23:22:03 +08:00
2017-01-26 12:00:03 +08:00
### 请求:
<p>{<br />
2017-03-04 20:25:00 +08:00
&nbsp; &nbsp; &quot;[]&quot;: { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //请求一个array<br />
2017-03-05 00:15:00 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &quot;page&quot;: 1, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//array条件<br />
2017-03-04 22:17:58 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &quot;count&quot;: 2, &nbsp; &nbsp; &nbsp; &nbsp;<br />
2017-03-04 20:27:17 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &quot;User&quot;: { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//请求查询名为User的table返回名为User的JSONObject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;sex&quot;: 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //object条件<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; },<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &quot;Moment&quot;: {<br />
2017-03-04 20:32:39 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId@&quot;: &ldquo;/User/id&rdquo; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //缺省依赖路径从同级object的路径开始<br />
2016-11-25 00:21:39 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; },<br />
2017-03-04 20:33:56 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment[]&quot;: { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //请求一个名为Comment的array&nbsp;<br />
2017-03-04 22:17:58 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;page&quot;: 0,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;count&quot;: 3,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;: {<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;momentId@&quot;: &ldquo;[]/Moment/id&rdquo; &nbsp; //完整依赖路径<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
2016-11-25 00:21:39 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; }<br />
}</p>
2016-11-24 23:22:03 +08:00
2017-03-06 01:22:08 +08:00
[点击这里测试](http://139.196.140.118:8080/get/%7B%22%5B%5D%22%3A%7B%22User%22%3A%7B%22sex%22%3A0%7D%2C%22Moment%22%3A%7B%22userId%40%22%3A%22%252FUser%252Fid%22%7D%2C%22Comment%5B%5D%22%3A%7B%22Comment%22%3A%7B%22momentId%40%22%3A%22%255B%255D%252FMoment%252Fid%22%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%2C%22count%22%3A2%2C%22page%22%3A1%7D%7D)
2017-01-26 12:00:03 +08:00
### 返回:
<p>{<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &quot;[]&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &quot;0&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;User&quot;:{<br />
2017-02-11 20:27:21 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:38710,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;sex&quot;:0,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;phone&quot;:&quot;1300038710&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;name&quot;:&quot;Name-38710&quot;,<br />
2016-12-07 23:41:40 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;head&quot;:&quot;http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000&quot;<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Moment&quot;:{<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:470,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;title&quot;:&quot;Title-470&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-470&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:38710,<br />
2017-03-06 01:45:18 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;pictureList&quot;:[&quot;http://static.oschina.net/uploads/user/585/1170143_50.jpg?t=1390226446000&quot;]<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment[]&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;0&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:4,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:0,<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:470,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:310,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:14604,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-4&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-14604&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-93781&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;1&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:22,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:221,<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:470,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:332,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:5904,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-22&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-5904&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-11679&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;2&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:47,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:4,<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:470,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:10,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:5477,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-47&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-5477&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-80271&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &quot;1&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;User&quot;:{<br />
2017-02-11 20:27:21 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:70793,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;sex&quot;:0,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;phone&quot;:&quot;1300070793&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;name&quot;:&quot;Name-70793&quot;,<br />
2016-12-07 23:41:40 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;head&quot;:&quot;http://static.oschina.net/uploads/user/1174/2348263_50.png?t=1439773471000&quot;<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
2017-03-06 01:05:38 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Moment&quot;:{<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:170,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;title&quot;:&quot;Title-73&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-73&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:70793,<br />
2017-03-06 01:45:18 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;pictureList&quot;:[&quot;http://my.oschina.net/img/portrait.gif?t=1451961935000&quot;]<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment[]&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;0&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:44,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:0,<br />
2017-03-06 01:06:57 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:170,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:7073,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:6378,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-44&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-6378&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-88645&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;1&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:54,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:0,<br />
2017-03-06 01:06:57 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:170,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:3,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:62122,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-54&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-62122&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-82381&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;2&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Comment&quot;:{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;id&quot;:99,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;parentId&quot;:44,<br />
2017-03-06 01:06:57 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;momentId&quot;:170,<br />
2016-11-24 23:36:07 +08:00
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userId&quot;:793,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserId&quot;:7166,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;content&quot;:&quot;This is a Content...-99&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;targetUserName&quot;:&quot;targetUserName-7166&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;userName&quot;:&quot;userName-22949&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}</p>
2016-11-24 23:22:03 +08:00
2016-11-25 00:29:39 +08:00
2016-11-25 19:35:39 +08:00
2017-03-05 22:47:33 +08:00
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/apijson_all_pages_0.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/apijson_all_pages_1.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/apijson_all_pages_2.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/apijson_all_pages_3.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/server_idea_log_complex.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/mysql_workbench_request.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/mysql_workbench_user.jpg)
![](https://raw.githubusercontent.com/TommyLemon/APIJSON/master/picture/mysql_workbench_moment.jpg)
2017-01-26 12:00:03 +08:00
2017-03-04 19:59:01 +08:00
## 功能符
2017-03-04 21:42:02 +08:00
 键值对格式 | 功能与作用 | 使用示例
2017-03-04 21:02:57 +08:00
------------ | ------------ | ------------
2017-03-05 02:06:41 +08:00
"key[]":{}后面是标准的JSONObject | 查询数组 | "User[]":{"User":{"sex":0}}查询性别为男的一个的User数组请求完成后会变为 "User[]":{"0":{"User":{"id":38710,"sex":0,"name":"Tommy"...}}, "1":{"User":{"id":82001,"sex":0,"name":"Lemon"...}} ...}
"key{}":[]后面是标准的JSONArray作为key可取的范围 | 匹配范围 | "id{}":[38710,82001,70793]查询id符合38710,82001,70793中任意一个的Object。一般用于查询一个数组。请求{"[]":{"User":{"id{}":[38710,82001,70793]}}}会返回一个User数组例如上面那个。
"key()":"函数表达式" 函数表达式为 function(Type0:value0,Type1:value1...) | 远程调用函数 | "isPraised()":"contains(Collection:praiseUserIdList,userId)",请求完成后会调用 boolean contains(Collection collection, Object object) 函数,然后变为 "isPraised":true 这种假设点赞用户id列表包含了userId即这个User点了赞。函数参数类型为Object时可用 value 替代 Object:value。
"key@":"依赖路径",依赖路径为用/分隔的字符串 | 依赖引用 | "userId@":"/User/id"userId依赖引用同级User内的id值假设id=1则请求完成后会变成 "userId":1
"key$":"SQL搜索表达式"任意标准SQL搜索表达式字符串如 %key%, %k%e%y% 等 | 模糊搜索 | "name$":"%Tommy%"搜索包含Tommy的名字。一般用于查询一个数组。请求 {"[]":{"User":{"name$":"%Tommy%"}}} 会返回name包含"Tommy"的User数组。
2017-03-06 02:00:04 +08:00
"@key":key指定类型的Object | @key为JSONObject中的关键字,作用各不相同,但都不作为查询匹配条件 | ① 只查询id,sex,name这几列并且请求结果也按照这个顺序<br />"@columns":"id,sex,name"<br />返回<br />{<br /> &nbsp; "id":1,<br /> &nbsp; "sex":0,<br /> &nbsp; "name":"Lemon"<br />}<br /> ...<br /> ② 从pictureList获取第0张图片作为头像<br />{<br /> &nbsp; "pictureList":["url0","url1"],<br /> &nbsp; "@position":0, //这里@position为自定义关键词<br /> &nbsp; "head()":"get(Collection:pictureList,Object:@position)"<br />}<br />返回<br />{<br /> &nbsp; "pictureList":["url0","url1"],<br /> &nbsp; "head":"url0"<br />}<br /> ...
2017-03-04 19:59:01 +08:00
2017-01-26 12:00:03 +08:00
## 对比传统HTTP传输方式
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
开发流程 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
2017-01-26 12:00:03 +08:00
接口传输 | 等服务端编辑接口,然后更新文档,客户端再按照文档编辑请求和解析代码 | 客户端按照自己的需求编辑请求和解析代码。没有接口,更不需要文档!客户端再也不用和服务端沟通接口或文档问题了!
兼容旧版 | 服务端增加新接口用v2表示第2版接口然后更新文档 | 什么都不用做!
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
客户端请求 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
2017-01-26 12:00:03 +08:00
要求 | 客户端按照文档在对应url后面拼接键值对 | 客户端按照自己的需求在固定url后拼接JSON
结构 | base_url/lowercase_table_name?key0=value0&key1=value1...<br />&currentUserId=100&loginPassword=1234<br /><br />其中currentUserId和loginPassword只在请求部分接口时需要 | base_url/{TableName0:{key0:value0, key1:value1 ...}, TableName1:{...}...<br />, currentUserId:100, loginPassword:1234}<br /><br />其中currentUserId和loginPassword只在请求部分接口时需要
URL | 不同的请求对应不同的url | 相同的请求方法(GETPOST等)都用同一个url
键值对 | key=value | key:value
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
服务端操作 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
2017-01-26 12:00:03 +08:00
解析和返回 | 取出键值对把键值对作为条件用预设的的方式去查询数据库最后封装JSON并返回给客户端 | 把RequestParser#parse方法的返回值返回给客户端就行
返回JSON结构的设定方式 | 由服务端设定,客户端不能修改 | 由客户端设定,服务端不能修改
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
客户端解析 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
2017-01-26 12:00:03 +08:00
查看方式 | 查文档或等请求成功后看log | 看请求就行所求即所得。也可以等请求成功后看log
方法 | 解析JSONObject | 可以用JSONResponse解析JSONObject或传统方式
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
客户端对应不同需求的请求 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
2017-03-06 01:11:09 +08:00
User | http://localhost:8080/get/user?id=1 | [http://localhost:8080/get/{"User":{"id":1}}](http://139.196.140.118:8080/get/{"User":{"id":38710}})
Moment和对应的User | 分两次请求<br />Moment: http://localhost:8080/get/moment?userId=1<br />User: http://localhost:8080/get/user?id=1 | [http://localhost:8080/get/{"Moment":{"id":1}, "User":{"id@":"Moment/userId"}}](http://139.196.140.118:8080/get/%7B%22Moment%22%3A%7B%22id%22%3A15%7D%2C%22User%22%3A%7B%22id%40%22%3A%22Moment%252FuserId%22%7D%7D)
2017-03-06 01:24:09 +08:00
User列表 | http://localhost:8080/get/user/list?page=0&count=3&sex=0 | [http://localhost:8080/get/{"[]":{"page":0, "count":3, "User":{"sex":0}}}](http://139.196.140.118:8080/get/{"[]":{"page":0,"count":3,"User":{"sex":0}}})
2017-03-06 01:11:09 +08:00
Moment列表每个Moment包括发布者User和前3条Comment | Moment里必须有User的Object和Comment的Array<br /> http://localhost:8080/get/moment/list?page=0&count=3&commentCount=3 | [http://localhost:8080/get/{"[]":{"page":0, "count":3, "Moment":{}, "User":{"momentId@":"/Moment/id"}, "[]":{"count":3, "Comment":{"momentId@":"[]/Moment/id"}}}}](http://139.196.140.118:8080/get/%7B%22%5B%5D%22%3A%7B%22Moment%22%3A%7B%7D%2C%22User%22%3A%7B%22id%40%22%3A%22%252FMoment%252FuserId%22%7D%2C%22Comment%5B%5D%22%3A%7B%22Comment%22%3A%7B%22momentId%40%22%3A%22%255B%255D%252FMoment%252Fid%22%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%7D)
1个User发布的Moment列表每个Moment包括发布者User和前3条Comment | http://localhost:8080/get/moment/list?page=0&count=3&commentCount=3&userId=1 | 有以下几种方法:<br />①把以上请求里的"Moment":{}, "User":{"momentId@":"/Moment/id"}改为["Moment":{"userId":1}, "User":{"id":1}](http://139.196.140.118:8080/get/%7B%22%5B%5D%22%3A%7B%22Moment%22%3A%7B%22userId%22%3A38710%7D%2C%22User%22%3A%7B%22id%22%3A38710%7D%2C%22%5B%5D%22%3A%7B%22Comment%22%3A%7B%22momentId%40%22%3A%22%255B%255D%252FMoment%252Fid%22%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%7D) <br /><br />②或这样省去4条重复User<br />[http://localhost:8080/get/{"User":{"id":1}, "[]":{"page":0, "count":3, "Moment":{"userId":1}, "[]":{"count":3, "Comment":{"momentId@":"[]/Moment/id"}}}}](http://139.196.140.118:8080/get/%7B%22User%22%3A%7B%22id%22%3A38710%7D%2C%22%5B%5D%22%3A%7B%22Moment%22%3A%7B%22userId%22%3A38710%7D%2C%22%5B%5D%22%3A%7B%22Comment%22%3A%7B%22momentId%40%22%3A%22%255B%255D%252FMoment%252Fid%22%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%7D)<br /><br />③如果User之前已经获取到了还可以这样省去所有重复User<br />[http://localhost:8080/get/{"[]":{"page":0, "count":3, "Moment":{"userId":1}, "[]":{"count":3, "Comment":{"momentId@":"[]/Moment/id"}}}}](http://139.196.140.118:8080/get/%7B%22%5B%5D%22%3A%7B%22Moment%22%3A%7B%22userId%22%3A38710%7D%2C%22%5B%5D%22%3A%7B%22Comment%22%3A%7B%22momentId%40%22%3A%22%255B%255D%252FMoment%252Fid%22%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%2C%22count%22%3A3%2C%22page%22%3A0%7D%7D)
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
服务端对应不同请求的返回结果 | 传统方式 | APIJSON
2016-12-06 20:31:52 +08:00
-------- | ------------ | ------------
User | {"status":200, "message":"success", "data":{"id":1, "name":"xxx"...}} | {"status":200, "message":"success", "User":{"id":1, "name":"xxx"...}}
2017-03-06 00:21:16 +08:00
User和对应的Moment | 分别返回两次请求的结果<br />User: {"status":200, "message":"success", "data":{"id":1, "name":"xxx"...}}<br />Moment: {"status":200, "message":"success", "data":{"id":1, "name":"xxx"...}} | {"status":200, "message":"success", "User":{"id":1, "name":"xxx"...}, "Moment":{"id":1, "content":"xxx"...}}
2017-01-26 12:00:03 +08:00
User列表 | {"status":200, "message":"success", "data":[{"id":1, "name":"xxx"...}, {"id":2...}...]} | {"status":200, "message":"success", "[]":{"0":{"User":{"id":1, "name":"xxx"...}}, "1":{"User":{"id":2...}}...}}
2017-03-06 00:52:34 +08:00
Moment列表每个Moment包括发布者User和前3条Comment | {"status":200, "message":"success", "data":[{"id":1, "content":"xxx"..., "User":{...}, "Comment":[...]}, {"id":2...}...]} | {"status":200, "message":"success", "[]":{"0":{"Moment":{"id":1, "content":"xxx"...}, "User":{...}, "[]":{"0":{"Comment":{...}...}}}, "1":{...}...}}
2017-03-06 00:21:16 +08:00
1个User发布的Moment列表每个Moment包括发布者User和前3条Comment | {"status":200, "message":"success", "data":[{"id":1, "content":"xxx"..., "User":{...}, "Comment":[...]}, {"id":2...}...]} | 以上不同请求方法的结果:<br />①{"status":200, "message":"success", "[]":{"0":{"User":{"id":1, "name":"xxx"...}, "Moment":{...}, "[]":{"0":{"Comment":{...}...}}}, "1":{...}...}}<br /><br />②{"status":200, "message":"success", "User":{...}, "[]":{"0":{"Moment":{"id":1, "content":"xxx"...}, "[]":{"0":{"Comment":{...}...}}}, "1":{...}...}}<br /><br />③{"status":200, "message":"success", "[]":{"0":{"Moment":{"id":1, "content":"xxx"...}, "[]":{"0":{"Comment":{...}...}}}, "1":{...}...}}
2016-12-06 20:31:52 +08:00
2017-01-26 12:00:03 +08:00
## 使用方法
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
### 1.下载后解压APIJSON工程
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
Clone or download &gt; Download ZIP &gt; 解压到一个路径并记住这个路径。
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
#### 你可以跳过步骤2和步骤3用我的服务器IP地址 139.196.140.118:8080 来测试服务端对客户端请求的返回结果。
2016-12-17 20:25:40 +08:00
2017-01-26 12:00:03 +08:00
### 2.导入MySQL table文件
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
服务端需要MySQL Server和MySQLWorkbench没有安装的都先下载安装一个。<br />
我的配置是Windows 7 + MySQL Community Server 5.7.16 + MySQLWorkbench 6.3.7 和 OSX EI Capitan + MySQL Community Server 5.7.16 + MySQLWorkbench 6.3.8其中系统和软件都是64位的。
2016-12-09 22:34:22 +08:00
2017-01-26 12:00:03 +08:00
启动MySQLWorkbench &gt; 进入一个Connection &gt; 点击Server菜单 &gt; Data Import &gt; 选择刚才解压路径下的APIJSON-Master/table &gt; Start Import &gt; 刷新SCHEMAS, 左下方sys/tables会出现添加的table。
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
### 3.用Eclipse for JavaEE或IntellIJ IDEA Ultimate运行服务端工程
2016-11-25 01:07:32 +08:00
2017-01-26 15:41:57 +08:00
如果以上编辑器一个都没安装,运行前先下载安装一个。<br />
2017-01-30 22:17:18 +08:00
我的配置是Windows 7 + JDK 1.7.0_71 + Eclipse 4.6.1 + IntellIJ 2016.3 和 OSX EI Capitan + JDK 1.8.0_91 + Eclipse 4.6.1 + IntellIJ 2016.2.5
2016-11-25 01:07:32 +08:00
2016-12-07 23:13:50 +08:00
#### Eclipse for JavaEE
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
1.导入<br />
File > Import > Maven > Existing Maven Projects > Next > Browse > 选择刚才解压路径下的APIJSON-Master/APIJSON(Server)/APIJSON(Eclipse_JEE) > Finish
2016-12-07 23:13:50 +08:00
2017-01-26 12:00:03 +08:00
2.运行<br />
Run > Run As > Java Application > 选择APIJSONApplication > OK
2016-12-07 23:13:50 +08:00
#### IntellIJ IDEA Ultimate
2017-01-26 12:00:03 +08:00
1.导入<br />
Open > 选择刚才解压路径下的APIJSON-Master/APIJSON(Server)/APIJSON(Idea) > OK
2016-12-07 23:13:50 +08:00
2017-01-26 12:00:03 +08:00
2.运行<br />
2016-12-07 23:13:50 +08:00
Run > Run APIJSONApplication
2017-01-26 12:00:03 +08:00
### 4.用ADT Bundle或Android Studio运行客户端工程
2016-12-07 23:13:50 +08:00
2017-01-26 12:00:03 +08:00
可以跳过这个步骤直接下载下方提供的客户端App。
2016-12-17 20:33:22 +08:00
2017-01-26 12:00:03 +08:00
如果以上编辑器一个都没安装,运行前先下载安装一个。<br />
2017-01-30 22:17:18 +08:00
我的配置是Windows 7 + JDK 1.7.0_71 + ADT Bundle 20140702 + Android Studio 2.2 和 OSX EI Capitan +JDK 1.7.0_71 + ADT Bundle 20140702+JDK 1.8.0_91 + Android Studio 2.1.2其中系统和软件都是64位的。
2016-12-07 23:13:50 +08:00
#### ADT Bundle
2017-01-26 12:00:03 +08:00
1.导入<br />
File > Import > Android > Existing Android Code Into Workspace > Next > Browse > 选择刚才解压路径下的APIJSON-Master/APIJSON(Android)/APIJSON(ADT) > Finish
2016-12-07 23:13:50 +08:00
2017-01-26 12:00:03 +08:00
2.运行<br />
2016-12-07 23:13:50 +08:00
Run > Run As > Android Application
#### Android Studio
2017-01-26 12:00:03 +08:00
1.导入<br />
Open an existing Android Studio project > 选择刚才解压路径下的APIJSON-Master/APIJSON(Android)/APIJSON(AndroidStudio) > OK
2016-12-07 23:13:50 +08:00
2017-01-26 12:00:03 +08:00
2.运行<br />
2016-12-07 23:13:50 +08:00
Run > Run app
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
### 5.操作客户端App
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
选择发送APIJSON请求并等待显示结果。<br />
如果默认url不可用修改为一个可用的比如正在运行APIJSON服务端工程的电脑的IPV4地址然后点击查询按钮重新请求。
2016-11-25 01:07:32 +08:00
2017-01-26 12:00:03 +08:00
## 下载试用客户端App
2016-11-25 00:29:39 +08:00
2017-03-05 01:37:49 +08:00
[APIJSONClientApp.apk](http://files.cnblogs.com/files/tommylemon/APIJSONApp.apk)
2016-11-25 19:51:19 +08:00
2016-11-26 13:09:01 +08:00
2017-01-26 12:00:03 +08:00
### 关于APIJSON如果你有任何问题或建议都可以发我邮件 tommylemon@qq.com.
2016-11-26 13:09:01 +08:00
2017-01-26 14:21:55 +08:00
## 更新日志
[https://github.com/TommyLemon/APIJSON/commits/master](https://github.com/TommyLemon/APIJSON/commits/master)
2017-01-26 12:00:03 +08:00
## 欢迎Star欢迎Fork
2016-11-26 13:09:01 +08:00
2017-01-26 14:17:14 +08:00
[https://github.com/TommyLemon/APIJSON](https://github.com/TommyLemon/APIJSON)
2017-01-26 12:00:03 +08:00
# APIJSON让接口见鬼去吧