80,469
社区成员




RequestQueue mQueue = Volley.newRequestQueue(getBaseContext());
Request<JSONObject> request = new HuaguHttpPost(Method.POST, "http://192.168.1.118/1.php", new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("json", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.i("json",error.getMessage(),error);
}
}, map);
mQueue.add(request);
public function Func{
public static JSONObject json;
public static JSONObject postMap(Map<String, String> map, final Activity act){
RequestQueue mQueue = Volley.newRequestQueue(act);
Request<JSONObject> request = new HuaguHttpPost(Method.POST, Constant.ServerURL, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
json = response;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("json",error.getMessage(),error);
try {
json = new JSONObject().put("error", 1);
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(act, "服务器连接错误,请检查网络连接", Toast.LENGTH_LONG).show();
}
}, map);
mQueue.add(request);
//如果在这里输出json.tostring() 一定会报空指针。
return json;//可是这里好像没有返回。
}
}