我是Java新手。我想發送json數據到web服務器。 我的排球文章如下。Android Volley發佈json數據到服務器
public void postData(String url,JSONObject data,final VolleyCallback mResultCallback){
RequestQueue requstQueue = Volley.newRequestQueue(mContext);
JsonObjectRequest jsonobj = new JsonObjectRequest(Request.Method.POST, url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if(mResultCallback != null){
mResultCallback.notifySuccess(response);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(mResultCallback != null){
mResultCallback.notifyError(error);
}
}
}
){
//here I want to post data to sever
};
requstQueue.add(jsonobj);
}
這裏是我的MainActivity代碼
JSONObject data = null;
try {
String datas = "{'email': email,'password': password}";
data = new JSONObject(datas);
}catch (JSONException e){
e.printStackTrace();
}
String url = "http://example.com";
我想JSON數據發佈到我的POSTDATA方法。 如何發佈這個json數據到我的服務器?現在
'新的JsonObjectRequest(Request.Method.POST,url,null,'第三個參數,如果對於JSONObject參數。用你的jsondata替換null –