Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android org.json.JSONException:java.lang.String类型的值失败\u post无法转换为JSONObject_Android_Json_Android Volley_Jsonobject - Fatal编程技术网

Android org.json.JSONException:java.lang.String类型的值失败\u post无法转换为JSONObject

Android org.json.JSONException:java.lang.String类型的值失败\u post无法转换为JSONObject,android,json,android-volley,jsonobject,Android,Json,Android Volley,Jsonobject,我想用volley库将数据发送到服务器当我用volley库将数据发送到服务器时,我得到以下错误: org.json.JSONException: Value failure_post of type java.lang.String cannot be converted to JSONObject 这是我的java代码: public void insertClick(View view) { RequestQueue queue = Vo

我想用
volley库
将数据发送到服务器当我用
volley库
将数据发送到服务器时,我得到以下错误:

org.json.JSONException: Value failure_post of type 
                     java.lang.String cannot be converted to JSONObject
这是我的java代码:

public void insertClick(View view)
{
    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
    HashMap<String, JSONObject> jsonParams = new HashMap<String, JSONObject>();

    JSONObject params = new JSONObject();
    try
    {
        params.put("title","BOOK");
        params.put("intro","hellothere");
    }
    catch (JSONException e)
    {

        Log.i(LABLE, "erorr is : "+ e.getMessage().toString());
    }

    try {

        JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,

        new JSONObject(jsonParams),
        new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Toast.makeText(getApplicationContext() , " insert ok ",Toast.LENGTH_LONG).show();

            }
        },
        new Response.ErrorListener()
        {
            @Override
            public void onErrorResponse(VolleyError error) {
                //   Handle Error

                Log.i(LABLE, "erorr is : "+ error.getMessage().toString());

                Toast.makeText(getApplicationContext() , " insert failed ",Toast.LENGTH_LONG).show();
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json");

                return headers;
            }
        };
        queue.add(postRequest);
    }
    catch (Exception e)
    {
        Toast.makeText(this , "erorr in Json Object Request ",Toast.LENGTH_LONG).show();
    }
public void insertClick(视图)
{
RequestQueue=Volley.newRequestQueue(getApplicationContext());
HashMap jsonParams=新HashMap();
JSONObject参数=新的JSONObject();
尝试
{
参数put(“标题”、“书”);
参数put(“介绍”、“问候”);
}
捕获(JSONException e)
{
Log.i(标签“erorr is:”+e.getMessage().toString());
}
试一试{
JsonObjectRequest postRequest=新的JsonObjectRequest(Request.Method.POST,url,
新的JSONObject(jsonParams),
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
Toast.makeText(getApplicationContext(),“插入ok”,Toast.LENGTH_LONG.show();
}
},
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
//处理错误
Log.i(标签“erorr is:”+error.getMessage().toString());
Toast.makeText(getApplicationContext(),“插入失败”,Toast.LENGTH_LONG.show();
}
}) {
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json”);
返回标题;
}
};
添加(postRequest);
}
捕获(例外e)
{
makeText(这是“Json对象请求中的erorr”,Toast.LENGTH_LONG.show();
}

创建一个
JsonArray

将JSONObject添加到该数组中


然后将一个完整的
JsonObject
create from
JsonArray
发送到
JsonObjectRequest
创建一个
JsonArray

将JSONObject添加到该数组中


然后将一个完整的
JsonObject
create from
JsonArray
发送到
JsonObjectRequest
尝试将
params
而不是
jsonParams
放在
JsonObjectRequest
ie中

替换此

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,new JSONObject(jsonParams),...

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,params,...
或者在放入地图后从地图中检索,如下所示

jsonParams.get("key") 

尝试将
params
而不是
jsonParams
放入
JsonObjectRequest
ie中

替换此

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,new JSONObject(jsonParams),...

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,params,...
或者在放入地图后从地图中检索,如下所示

jsonParams.get("key") 

错误在哪里??新建JSONObject(jsonParams)这仅适用于MAPInstead的
新建JSONObject(jsonParams),
,IMO,您应仅使用
参数
新建JSONObject(params),
错误在哪里??新建JSONObject(jsonParams)这仅适用于MAPInstead的
新建JSONObject(jsonParams),
,依我看,您应该只使用
params
新JSONObject(params),