| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 99ba3ed commit 47b6082
40 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |||
| 174 | 174 | JSONResponse response = new JSONResponse(resultJson); | |
| 175 | 175 | User user = response.getObject(User.class); | |
| 176 | 176 | ||
| 177 | - if (response.isSucceed() == false) { | ||
| 177 | + if (response.isSuccess() == false) { | ||
| 178 | 178 | switch (response.getCode()) { | |
| 179 | 179 | case JSONResponse.CODE_NOT_FOUND: | |
| 180 | 180 | showShortToast("账号不存在,请先注册"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -321,7 +321,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |||
| 321 | 321 | switch (requestCode) { | |
| 322 | 322 | case HTTP_LOUOUT: | |
| 323 | 323 | JSONResponse response = new JSONResponse(resultJson).getJSONResponse(Login.class.getSimpleName()); | |
| 324 | - boolean succeed = JSONResponse.isSucceed(response); | ||
| 324 | + boolean succeed = JSONResponse.isSuccess(response); | ||
| 325 | 325 | Log.d(TAG, succeed ? "服务端退出成功" : "服务端退出失败"); | |
| 326 | 326 | showShortToast(succeed ? "服务端退出成功" : "服务端退出失败"); | |
| 327 | 327 | break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -367,7 +367,7 @@ public void getListAsync(final int page) { | |||
| 367 | 367 | ||
| 368 | 368 | @Override | |
| 369 | 369 | public List<CommentItem> parseArray(String json) { | |
| 370 | - return JSON.parseArray(new JSONResponse(json).getArray(CommentItem.class.getSimpleName()), CommentItem.class); | ||
| 370 | + return new JSONResponse(json).getList(CommentItem.class); | ||
| 371 | 371 | } | |
| 372 | 372 | ||
| 373 | 373 | @Override | |
@@ -520,7 +520,7 @@ public void run() { | |||
| 520 | 520 | if (requestCode == HTTP_GET_MOMENT) { | |
| 521 | 521 | MomentItem data = JSONResponse.toObject(response, MomentItem.class); | |
| 522 | 522 | if (data == null || data.getId() <= 0) { | |
| 523 | - if (JSONResponse.isSucceed(response)) { | ||
| 523 | + if (JSONResponse.isSuccess(response)) { | ||
| 524 | 524 | showShortToast("动态不存在"); | |
| 525 | 525 | MomentActivity.super.finish();//需要动画,且不需要保存缓存 | |
| 526 | 526 | return; | |
@@ -534,7 +534,7 @@ public void run() { | |||
| 534 | 534 | ||
| 535 | 535 | ||
| 536 | 536 | JSONResponse comment = response.getJSONResponse(Comment.class.getSimpleName()); | |
| 537 | - final boolean succeed = JSONResponse.isSucceed(comment); | ||
| 537 | + final boolean succeed = JSONResponse.isSuccess(comment); | ||
| 538 | 538 | String operation = "操作"; | |
| 539 | 539 | switch (requestCode) { | |
| 540 | 540 | case HTTP_COMMENT: // 新增评论 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -367,7 +367,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
| 367 | 367 | JSONRequest search = new JSONRequest(); | |
| 368 | 368 | if (StringUtil.isNotEmpty(value, true)) { | |
| 369 | 369 | split = ":"; | |
| 370 | - search.putSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER); | ||
| 370 | + search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER); | ||
| 371 | 371 | } | |
| 372 | 372 | toActivity(MomentListActivity.createIntent(context, range, id, search, false) | |
| 373 | 373 | .putExtra(INTENT_TITLE, "搜索" + split + value)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -312,7 +312,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |||
| 312 | 312 | dismissProgressDialog(); | |
| 313 | 313 | switch (requestCode) { | |
| 314 | 314 | case HTTP_SET_PASSWORD: | |
| 315 | - if (response.isSucceed()) { | ||
| 315 | + if (response.isSuccess()) { | ||
| 316 | 316 | showShortToast(R.string.change_succeed); | |
| 317 | 317 | saveAndExit(true); | |
| 318 | 318 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -351,7 +351,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |||
| 351 | 351 | @Override | |
| 352 | 352 | public void run() { | |
| 353 | 353 | showVerifyGet(false); | |
| 354 | - if (JSONResponse.isSucceed(response2) == false) { | ||
| 354 | + if (JSONResponse.isSuccess(response2) == false) { | ||
| 355 | 355 | showShortToast(R.string.get_failed); | |
| 356 | 356 | } else if (JSONResponse.isExist(response2)) { | |
| 357 | 357 | if (type == TYPE_REGISTER) { | |
@@ -412,7 +412,7 @@ public void run() { | |||
| 412 | 412 | case HTTP_REGISTER: | |
| 413 | 413 | User user = response.getObject(User.class); | |
| 414 | 414 | dismissProgressDialog(); | |
| 415 | - if (user == null || user.getId() <= 0 || JSONResponse.isSucceed( | ||
| 415 | + if (user == null || user.getId() <= 0 || JSONResponse.isSuccess( | ||
| 416 | 416 | response.getJSONResponse(User.class.getSimpleName())) == false) { | |
| 417 | 417 | if (response.getCode() == CODE_TIME_OUT || response.getCode() == 412) { | |
| 418 | 418 | EditTextUtil.showInputedError(context, etPasswordVerify | |
@@ -430,7 +430,7 @@ public void run() { | |||
| 430 | 430 | case HTTP_RESET_PASSWORD: | |
| 431 | 431 | response2 = response.getJSONResponse(Privacy.class.getSimpleName()); | |
| 432 | 432 | dismissProgressDialog(); | |
| 433 | - if (JSONResponse.isSucceed(response2) == false) { | ||
| 433 | + if (JSONResponse.isSuccess(response2) == false) { | ||
| 434 | 434 | EditTextUtil.showInputedError(context, etPasswordVerify | |
| 435 | 435 | , response.getCode() == CODE_TIME_OUT ? "验证码已过期" : "验证码错误"); | |
| 436 | 436 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -450,14 +450,14 @@ public void onBottomMenuItemClick(int intentCode) { | |||
| 450 | 450 | public void onHttpResponse(int requestCode, String resultJson, Exception e) { | |
| 451 | 451 | JSONResponse response = new JSONResponse(resultJson); | |
| 452 | 452 | JSONResponse response2 = response.getJSONResponse(User.class.getSimpleName()); | |
| 453 | - boolean isSucceed = JSONResponse.isSucceed(response2); | ||
| 453 | + boolean isSucceed = JSONResponse.isSuccess(response2); | ||
| 454 | 454 | ||
| 455 | 455 | dismissProgressDialog(); | |
| 456 | 456 | switch (requestCode) { | |
| 457 | 457 | case HTTP_GET: | |
| 458 | 458 | User user = response.getObject(User.class); | |
| 459 | 459 | if (user == null || user.getId() <= 0) { | |
| 460 | - if (JSONResponse.isSucceed(response)) { | ||
| 460 | + if (JSONResponse.isSuccess(response)) { | ||
| 461 | 461 | showShortToast("用户已注销"); | |
| 462 | 462 | super.finish();//需要动画,且不需要保存缓存 | |
| 463 | 463 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -383,9 +383,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
| 383 | 383 | if (StringUtil.isNotEmpty(value, true)) { | |
| 384 | 384 | split = ":"; | |
| 385 | 385 | if (isSearch) { | |
| 386 | - search.putSearch(HttpRequest.NAME, value); | ||
| 386 | + search.putsSearch(HttpRequest.NAME, value); | ||
| 387 | 387 | } else { | |
| 388 | - search.put(HttpRequest.PHONE, value); | ||
| 388 | + search.puts(HttpRequest.PHONE, value); | ||
| 389 | 389 | } | |
| 390 | 390 | } | |
| 391 | 391 | intent = isSearch | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,7 +167,7 @@ public void onHttpResponse(final int requestCode, final String resultJson, Excep | |||
| 167 | 167 | public void run() { | |
| 168 | 168 | ||
| 169 | 169 | JSONResponse response = new JSONResponse(resultJson); | |
| 170 | - isSucceed = JSONResponse.isSucceed(response); | ||
| 170 | + isSucceed = JSONResponse.isSuccess(response); | ||
| 171 | 171 | ||
| 172 | 172 | dismissProgressDialog(); | |
| 173 | 173 | switch (requestCode) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,37 +15,32 @@ | |||
| 15 | 15 | ||
| 16 | 16 | package apijson.demo.client.manager; | |
| 17 | 17 | ||
| 18 | - import android.content.Context; | ||
| 19 | - import android.os.AsyncTask; | ||
| 20 | - import android.text.TextUtils; | ||
| 21 | - | ||
| 22 | - import com.squareup.okhttp.MediaType; | ||
| 23 | - import com.squareup.okhttp.OkHttpClient; | ||
| 24 | - import com.squareup.okhttp.Request; | ||
| 25 | - import com.squareup.okhttp.RequestBody; | ||
| 26 | - import com.squareup.okhttp.Response; | ||
| 27 | - | ||
| 28 | - import org.json.JSONException; | ||
| 29 | - import org.json.JSONObject; | ||
| 30 | - | ||
| 31 | 18 | import java.io.IOException; | |
| 32 | 19 | import java.net.CookieHandler; | |
| 33 | 20 | import java.net.URI; | |
| 34 | - import java.net.URLEncoder; | ||
| 35 | 21 | import java.util.ArrayList; | |
| 36 | 22 | import java.util.HashMap; | |
| 37 | 23 | import java.util.List; | |
| 38 | 24 | import java.util.Map; | |
| 39 | 25 | import java.util.concurrent.TimeUnit; | |
| 40 | 26 | ||
| 41 | - import apijson.demo.client.application.APIJSONApplication; | ||
| 42 | - import zuo.biao.apijson.JSON; | ||
| 43 | - import zuo.biao.apijson.JSONRequest; | ||
| 27 | + import org.json.JSONException; | ||
| 28 | + | ||
| 44 | 29 | import zuo.biao.apijson.StringUtil; | |
| 45 | 30 | import zuo.biao.library.manager.HttpManager.OnHttpResponseListener; | |
| 46 | 31 | import zuo.biao.library.util.Log; | |
| 32 | + import android.content.Context; | ||
| 33 | + import android.os.AsyncTask; | ||
| 34 | + import android.text.TextUtils; | ||
| 35 | + import apijson.demo.client.application.APIJSONApplication; | ||
| 47 | 36 | ||
| 48 | - import static zuo.biao.apijson.StringUtil.UTF_8; | ||
| 37 | + import com.alibaba.fastjson.JSON; | ||
| 38 | + import com.alibaba.fastjson.JSONObject; | ||
| 39 | + import com.squareup.okhttp.MediaType; | ||
| 40 | + import com.squareup.okhttp.OkHttpClient; | ||
| 41 | + import com.squareup.okhttp.Request; | ||
| 42 | + import com.squareup.okhttp.RequestBody; | ||
| 43 | + import com.squareup.okhttp.Response; | ||
| 49 | 44 | ||
| 50 | 45 | /**HTTP请求管理类 | |
| 51 | 46 | * @author Lemon | |
@@ -85,58 +80,6 @@ public static HttpManager getInstance() { | |||
| 85 | 80 | public static final String KEY_COOKIE = "cookie"; | |
| 86 | 81 | ||
| 87 | 82 | ||
| 88 | - /**GET请求 | ||
| 89 | - * @param url_ 接口url | ||
| 90 | - * @param request 请求 | ||
| 91 | - * @param requestCode | ||
| 92 | - * 请求码,类似onActivityResult中请求码,当同一activity中以实现接口方式发起多个网络请求时,请求结束后都会回调 | ||
| 93 | - * {@link OnHttpResponseListener#onHttpResponse(int, String, Exception)}<br/> | ||
| 94 | - * 在发起请求的类中可以用requestCode来区分各个请求 | ||
| 95 | - * @param listener | ||
| 96 | - */ | ||
| 97 | - public void get(final String url_, final com.alibaba.fastjson.JSONObject request | ||
| 98 | - , final int requestCode, final OnHttpResponseListener listener) { | ||
| 99 | - new AsyncTask<Void, Void, Exception>() { | ||
| 100 | - | ||
| 101 | - String result; | ||
| 102 | - @Override | ||
| 103 | - protected Exception doInBackground(Void... params) { | ||
| 104 | - String body = request == null || request.isEmpty() ? null : JSON.toJSONString(request); | ||
| 105 | - Log.d(TAG, "\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n get url = " + url_ + "\n request = \n" + body); | ||
| 106 | - try { | ||
| 107 | - String url = StringUtil.getNoBlankString(url_) | ||
| 108 | - + (body == null ? "" : URLEncoder.encode(StringUtil.getNoBlankString(body), UTF_8)); | ||
| 109 | - StringBuffer sb = new StringBuffer(); | ||
| 110 | - sb.append(url); | ||
| 111 | - | ||
| 112 | - OkHttpClient client = getHttpClient(url); | ||
| 113 | - if (client == null) { | ||
| 114 | - return new Exception(TAG + ".get AsyncTask.doInBackground client == null >> return;"); | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - result = getResponseJson(client, new Request.Builder() | ||
| 118 | - .addHeader(KEY_TOKEN, getToken(url)) | ||
| 119 | - .url(sb.toString()).build()); | ||
| 120 | - Log.d(TAG, "\n get result = \n" + result + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n"); | ||
| 121 | - } catch (Exception e) { | ||
| 122 | - Log.e(TAG, "get AsyncTask.doInBackground try { result = getResponseJson(..." + | ||
| 123 | - "} catch (Exception e) {\n" + e.getMessage()); | ||
| 124 | - return e; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - return null; | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - @Override | ||
| 131 | - protected void onPostExecute(Exception exception) { | ||
| 132 | - super.onPostExecute(exception); | ||
| 133 | - listener.onHttpResponse(requestCode, result, exception); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - }.execute(); | ||
| 137 | - | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | 83 | public static final MediaType TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); | |
| 141 | 84 | ||
| 142 | 85 | /**POST请求 | |
@@ -150,11 +93,6 @@ protected void onPostExecute(Exception exception) { | |||
| 150 | 93 | */ | |
| 151 | 94 | public void post(final String url_, final com.alibaba.fastjson.JSONObject request | |
| 152 | 95 | , final int requestCode, final OnHttpResponseListener listener) { | |
| 153 | - if (request == null || request.containsKey(JSONRequest.KEY_TAG) == false) { | ||
| 154 | - throw new IllegalArgumentException("post " + url_ + " \n" + | ||
| 155 | - " request == null || request.containsKey(JSONRequest.KEY_TAG) == false !!!"); | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | 96 | new AsyncTask<Void, Void, Exception>() { | |
| 159 | 97 | ||
| 160 | 98 | String result; | |
@@ -280,7 +218,7 @@ private String getResponseJson(OkHttpClient client, Request request) throws Exce | |||
| 280 | 218 | * @throws JSONException | |
| 281 | 219 | */ | |
| 282 | 220 | public <T> T getValue(String json, String key) throws JSONException { | |
| 283 | - return getValue(new JSONObject(json), key); | ||
| 221 | + return getValue(JSON.parseObject(json), key); | ||
| 284 | 222 | } | |
| 285 | 223 | /**从object中获取key对应的值 | |
| 286 | 224 | * *获取如果T是基本类型容易崩溃,所以需要try-catch | |
| Back | FazBrowse Home | New Git URL |
0 commit comments