data={ "request": { "type": "event_and_offer","devicetype": "A" },"requestinfo": { "value": "offer" }}
如何从volley plz帮助发布此请求
JsonObjectRequest JsonObjReq = new JsonObjectRequest( Request.Method.POST,url,null,new Response.Listener<JsONObject>() { @OverrIDe public voID onResponse(JsONObject response) { Log.d(TAG,response.toString()); msgResponse.setText(response.toString()); hIDeProgressDialog(); } },new Response.ErrorListener() { @OverrIDe public voID onErrorResponse(VolleyError error) { VolleyLog.d(TAG,"Error: " + error.getMessage()); hIDeProgressDialog(); } }) { /** * Passing some request headers * */ @OverrIDe public Map<String,String> getheaders() throws AuthFailureError { HashMap<String,String> headers = new HashMap<String,String>(); headers.put("Content-Type","application/x-www-form-urlencoded"); return headers; }
Js是我的Jsson对象……我让我的Jsson像这样……
JsONObject Jsonobject_one = new JsONObject(); try { Jsonobject_one.put("type","event_and_offer"); Jsonobject_one.put("devicetype","I"); JsONObject Jsonobject_TWO = new JsONObject(); Jsonobject_TWO.put("value","event"); Jsonobject = new JsONObject(); Jsonobject.put("requestinfo",Jsonobject_TWO); Jsonobject.put("request",Jsonobject_one); Js = new JsONObject(); Js.put("data",Jsonobject.toString()); Log.e("created Jsson","" + Js);
但它没有回应plzz帮助的价值
解决方法 首先你的Json数据:JsONObject Js = new JsONObject();try { JsONObject Jsonobject_one = new JsONObject(); Jsonobject_one.put("type","event_and_offer"); Jsonobject_one.put("devicetype","I"); JsONObject Jsonobject_TWO = new JsONObject(); Jsonobject_TWO.put("value","event"); JsONObject Jsonobject = new JsONObject(); Jsonobject.put("requestinfo",Jsonobject_TWO); Jsonobject.put("request",Jsonobject_one); Js.put("data",Jsonobject.toString());}catch (JsONException e) { e.printstacktrace();}
然后你的Json请求:
JsonObjectRequest JsonObjReq = new JsonObjectRequest( Request.Method.POST,Js,new Response.Listener<JsONObject>() { @OverrIDe public voID onResponse(JsONObject response) { Log.d(TAG,response.toString()); msgResponse.setText(response.toString()); hIDeProgressDialog(); } },new Response.ErrorListener() { @OverrIDe public voID onErrorResponse(VolleyError error) { VolleyLog.d(TAG,"Error: " + error.getMessage()); hIDeProgressDialog(); } }) { /** * Passing some request headers * */ @OverrIDe public Map<String,String> getheaders() throws AuthFailureError { HashMap<String,String>(); headers.put("Content-Type","application/Json; charset=utf-8"); return headers; }
注意标题
如果你想在localhost中测试使用下面的代码并设置你的url连接你的localhost服务器和IP地址:
下面的代码将您的所有请求放在一个文本文件中,我尝试了它,它的工作原理
<?PHPfile_put_contents('test.txt',file_get_contents('PHP://input'));?>总结
以上是内存溢出为你收集整理的android – 用于json对象的Volley Post方法全部内容,希望文章能够帮你解决android – 用于json对象的Volley Post方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)