问题描述
- Android中的AsyncHttpClient框架下怎么post后台数据?
-
下面是后台拍的代码
public void baseInfo(Context context,RequestParams params, final HttpUtil.ReponseCallback callback){
HttpUtil.get(context,spellUrl(baseInfo_url), params, new TextHttpResponseHandler() {
@Override
public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
callback.onFailure(s,throwable);
}
@Override
public void onSuccess(int i, Header[] headers, String s) {
EmpVo empVo = parseJsonToEmpVo(s);
callback.onSuccess(empVo);
}
});
}private String baseInfo_url="handler/EmpInfo.ashx"; private EmpVo parseJsonToEmpVo(String result){ EmpVo empVo=null; try { JSONObject obj=new JSONObject(result); int ret=obj.getInt("result"); if(ret==0){ //LogUtil.d(TAG,obj.getString("HREmployee").toString()); empVo=gson.fromJson(obj.getString("HREmployee"),type_empVo); } } catch (JSONException e) { e.printStackTrace(); } return empVo; } RequestParams params=new RequestParams(); params.put("sessionID", AppUtil.getUserVo().getSessionID()); params.put("info", getResources().getString(R.string.hremployee)); params.put(MyFilesActivity.EXTRA_XIASHUEMPID, xiaShuEmpId); myFilesAction.baseInfo(this, params, new HttpUtil.ReponseCallback<EmpVo>() { @Override public void onSuccess(EmpVo emp) { progressDialog.hideProgressDialog(); if (emp != null) { empVo = emp; showInfo(); } else { toast("暂无数据"); } }
然后上面这几段是原来写好的能运行的获取后台json并解析成emp的代码
解决方案
解决方案二:
android 后台post 数据
解决方案三:
这个 当时学的时候 没太注意,就几句代码. 给我邮箱吧
时间: 2024-09-20 19:22:42