栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JSON对象的Volley Post方法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JSON对象的Volley Post方法

首先你的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,url, 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(); }        }) {        @Override    public Map<String, String> getHeaders() throws AuthFailureError {         HashMap<String, String> headers = new 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'));?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/633542.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号