Skip to content

Commit b70ee76

Browse files
committed
Server:新增指定字段;优化权限验证提示;新增请求方法;Client:新增指定字段示例
1 parent 086158c commit b70ee76

16 files changed

Lines changed: 263 additions & 77 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/gen/apijson/demo/R.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ public static final class layout {
3030
public static final int select_activity=0x7f030001;
3131
}
3232
public static final class string {
33-
public static final int access_error=0x7f050008;
34-
public static final int access_permitted=0x7f050009;
33+
public static final int access_error=0x7f050009;
34+
public static final int access_permitted=0x7f05000a;
3535
public static final int action_settings=0x7f050003;
3636
public static final int app_name=0x7f050000;
3737
public static final int app_version=0x7f050001;
38-
public static final int array=0x7f050006;
39-
public static final int complex=0x7f050007;
40-
public static final int demo_array=0x7f05000e;
41-
public static final int demo_complex=0x7f05000f;
42-
public static final int demo_rely=0x7f05000d;
43-
public static final int demo_single=0x7f05000c;
44-
public static final int demo_wallet=0x7f050010;
45-
public static final int demo_wallet_with_access=0x7f050011;
38+
public static final int array=0x7f050007;
39+
public static final int columns=0x7f050005;
40+
public static final int complex=0x7f050008;
41+
public static final int demo_array=0x7f050010;
42+
public static final int demo_columns=0x7f05000e;
43+
public static final int demo_complex=0x7f050011;
44+
public static final int demo_rely=0x7f05000f;
45+
public static final int demo_single=0x7f05000d;
46+
public static final int demo_wallet=0x7f050012;
47+
public static final int demo_wallet_with_access=0x7f050013;
4648
public static final int hello_world=0x7f050002;
47-
public static final int query=0x7f05000a;
48-
public static final int query_error=0x7f05000b;
49-
public static final int rely=0x7f050005;
49+
public static final int query=0x7f05000b;
50+
public static final int query_error=0x7f05000c;
51+
public static final int rely=0x7f050006;
5052
public static final int single=0x7f050004;
5153
}
5254
public static final class style {

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/layout/select_activity.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
android:onClick="selectSingle"
1818
android:text="@string/demo_single" />
1919

20+
<TextView
21+
style="@style/select_name"
22+
android:text="@string/columns" />
23+
24+
<Button
25+
style="@style/select_json"
26+
android:onClick="selectColumns"
27+
android:text="@string/demo_columns" />
28+
2029
<TextView
2130
style="@style/select_name"
2231
android:text="@string/rely" />

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<string name="hello_world">Hello world!</string>
77
<string name="action_settings">Settings</string>
88
<string name="single">单个Object</string>
9-
<string name="rely">Object之间的依赖</string>
9+
<string name="columns">指定字段</string>
10+
<string name="rely">向上依赖</string>
1011
<string name="array">Object数组</string>
1112
<string name="complex">复杂结构</string>
1213
<string name="access_error">没有访问权限</string>

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<string name="hello_world">Hello world!</string>
77
<string name="action_settings">Settings</string>
88
<string name="single">Single</string>
9+
<string name="columns">Columns</string>
910
<string name="rely">Rely</string>
1011
<string name="array">Array</string>
1112
<string name="complex">Complex</string>
@@ -14,6 +15,7 @@
1415
<string name="query">Query</string>
1516
<string name="query_error">There may be something wrong,you can follow by the steps:\n\n1.Check your net connection\n\n2.Check the url whether it\'s an available ipv4 address\n\n3.Long click the [Query] button to open the request by web browser\n\n4.Check logs outputed on the target server\n\n5.Try again</string>
1617
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
18+
<string name="demo_columns">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"columns\":\"id,name,phone\",\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
1719
<string name="demo_rely">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":70793\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"User/id\"\n&#160;&#160;&#160;}\n}</string>
1820
<string name="demo_array">{\n&#160;&#160;&#160;\"User[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":5,\n&#160;&#160;&#160;&#160;&#160;&#160;\"page\":1,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
1921
<string name="demo_complex">{\n&#160;&#160;&#160;\"[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":2,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"/User/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Comment[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"count\":3,\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"Comment\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"workId\":\"[]/Work/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/RequestUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public class RequestUtil {
2929
public static JSONObject newSingleRequest() {
3030
return new JSONRequest(new User((long) 38710));
3131
}
32+
33+
public static JSONObject newColumnsRequest() {
34+
JSONObject object = new JSONObject(new User((long) 38710));
35+
object.setColumns("id,name,phone");//StringUtil.getString(new String[]{"id", "name", "phone"}));//
36+
return new JSONRequest(User.class.getSimpleName(), object);
37+
}
3238

3339
public static JSONObject newRelyRequest() {
3440
JSONRequest request = new JSONRequest();

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/QueryActivity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public static Intent createIntent(Context context, int type, String url) {
7373

7474

7575
public static final int TYPE_SINGLE = 0;
76-
public static final int TYPE_RELY = 1;
77-
public static final int TYPE_ARRAY = 2;
78-
public static final int TYPE_COMPLEX = 3;
79-
public static final int TYPE_ACCESS_ERROR = 4;
80-
public static final int TYPE_ACCESS_PERMITTED = 5;
76+
public static final int TYPE_COLUMNS = 1;
77+
public static final int TYPE_RELY = 2;
78+
public static final int TYPE_ARRAY = 3;
79+
public static final int TYPE_COMPLEX = 4;
80+
public static final int TYPE_ACCESS_ERROR = 5;
81+
public static final int TYPE_ACCESS_PERMITTED = 6;
8182

8283

8384
private int type = TYPE_SINGLE;
@@ -144,6 +145,9 @@ public void setRequest() {
144145
case TYPE_SINGLE:
145146
request = JSON.toJSONString(RequestUtil.newSingleRequest());
146147
break;
148+
case TYPE_COLUMNS:
149+
request = JSON.toJSONString(RequestUtil.newColumnsRequest());
150+
break;
147151
case TYPE_RELY:
148152
request = JSON.toJSONString(RequestUtil.newRelyRequest());
149153
break;

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/SelectActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public void selectSingle(View v) {
4848
select(QueryActivity.TYPE_SINGLE);
4949
}
5050

51+
public void selectColumns(View v) {
52+
select(QueryActivity.TYPE_COLUMNS);
53+
}
54+
5155
public void selectRely(View v) {
5256
select(QueryActivity.TYPE_RELY);
5357
}

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/StringUtil.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,31 @@ public static String getString(CharSequence cs) {
107107
public static String getString(String s) {
108108
return s == null ? "" : s;
109109
}
110-
110+
/**获取string,为null则返回""
111+
* @param array
112+
* @return
113+
*/
114+
public static String getString(String[] array) {
115+
return getString(array, null);
116+
}
117+
/**获取string,为null则返回""
118+
* @param array
119+
* @param split
120+
* @return
121+
*/
122+
public static String getString(String[] array, String split) {
123+
String s = "";
124+
if (array != null) {
125+
if (split == null) {
126+
split = ",";
127+
}
128+
for (int i = 0; i < array.length; i++) {
129+
s += ((i >= array.length - 1 ? "" : split) + array[i]);
130+
}
131+
}
132+
return getString(s);
133+
}
134+
111135
//获取string,为null时返回"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
112136

113137
//获取去掉前后空格后的string<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/client/JSONObject.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public class JSONObject extends com.alibaba.fastjson.JSONObject {
3535
public JSONObject() {
3636
super(true);
3737
}
38+
/**transfer Object to JSONObject
39+
* @param object
40+
*/
41+
public JSONObject(Object object) {
42+
this(JSON.toJSONString(object));
43+
}
44+
/**parse JSONObject with JSON String
45+
* @param json
46+
*/
3847
public JSONObject(String json) {
3948
this(JSON.parseObject(json));
4049
}
@@ -48,6 +57,7 @@ public JSONObject(com.alibaba.fastjson.JSONObject object) {
4857

4958

5059

60+
5161
/**
5262
* @param key
5363
* @return if value is String, return URLDecoder.decode((String) value, UTF_8);
@@ -100,6 +110,21 @@ public void add(com.alibaba.fastjson.JSONObject object) {
100110
}
101111
}
102112
}
113+
114+
115+
public static final String KEY_COLUMNS = "columns";
116+
/**set columns need to be returned
117+
* @param columns "column0,column1,column2..."
118+
* @return
119+
*/
120+
public JSONObject setColumns(String columns) {
121+
put(KEY_COLUMNS, columns);
122+
return this;
123+
}
124+
public String getColumns() {
125+
return getString(KEY_COLUMNS);
126+
}
127+
103128

104129

105130
//array object <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/StringUtil.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@ public static String getString(CharSequence cs) {
9393
public static String getString(String s) {
9494
return s == null ? "" : s;
9595
}
96+
/**获取string,为null则返回""
97+
* @param array
98+
* @return
99+
*/
100+
public static String getString(String[] array) {
101+
return getString(array, null);
102+
}
103+
/**获取string,为null则返回""
104+
* @param array
105+
* @param split
106+
* @return
107+
*/
108+
public static String getString(String[] array, String split) {
109+
String s = "";
110+
if (array != null) {
111+
if (split == null) {
112+
split = ",";
113+
}
114+
for (int i = 0; i < array.length; i++) {
115+
s += ((i >= array.length - 1 ? "" : split) + array[i]);
116+
}
117+
}
118+
return getString(s);
119+
}
96120

97121
//获取string,为null时返回"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
98122

@@ -251,7 +275,7 @@ public static boolean isEmail(String email) {
251275

252276
return p.matcher(email).matches();
253277
}
254-
278+
255279
/**判断是否全是数字
256280
* @param s
257281
* @return
@@ -508,7 +532,7 @@ public static String getCorrectEmail(String email) {
508532
public static final int PRICE_FORMAT_PREFIX_WITH_BLANK = 3;
509533
public static final int PRICE_FORMAT_SUFFIX_WITH_BLANK = 4;
510534
public static final String[] PRICE_FORMATS = {
511-
"", "¥", "元", "¥ ", " 元"
535+
"", "¥", "元", "¥ ", " 元"
512536
};
513537

514538
/**获取价格,保留两位小数

0 commit comments

Comments
 (0)