?Map paramsparams= new HashMap<>(); ? ?傳入得參數(shù)
params.put("key", value);?
OkHttpUtils.post() ? ? ? ? ? ? ? //請求數(shù)據(jù)
? ? ? ? .url(URL路徑)
? ? ? ? .params(params)
? ? ? ? .build()
? ? ? ? .execute(new StringCallback() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onError(Call call, Exception e, int id) {
//失敗時(shí)
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onResponse(String response, int id) { ?
//json原生解析
? ? ? ? ? ? ? ? JSONObject jsonObject= JSONObject.parseObject(response);
? ? ? ? ? ? ? ? String code= jsonObject.getString("errorCode");
? ? ? ? ? ? ? ? if (code.equals("2000")) {
? ? ? ? ? ? ? ? ? ? Num= jsonObject.getString("json");
? ? ? ? ? ? ? ? } ?
//gson解析
UserInfoBean bean= new Gson().fromJson(response, UserInfoBean.class);
}
? ? ? ? });