使用Volley进行POST和JSONObject响应时出错


Error when using Volley for POST and JSONObject Response

我正试图将一些数据从我的android应用程序发布到我的web服务器,然后发送一个值响应,但我一直收到这个错误

Error: org.json.JSONException: Value SQLSTATE of type java.lang.String cannot be converted to JSONObject

这是与相关的安卓代码

                JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                        url, null,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                Log.d(TAG, response.toString());
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d(TAG, "Error: " + error.getMessage());
                    }
                }) {
                    @Override
                    protected Map<String, String> getParams() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("name", regName);
                        params.put("email", regEmail);
                        params.put("password", regPassword1);
                        return params;
                    }
                };
                AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);

以下是相关的php代码

    <?php

$iname = $_POST['name'];
$iemail = $_POST['email'];
$ipassword = $_POST['password'];
try {

$list = array();
$x = 1;
$name = "Epic App";
$image = "http://www.example.com/feed/img/c123.jpg";
$profilePic = "http://www.example.com/feed/img/nat.jpg";
$timeStamp = "1403375851930";
while($x<=10){
    $list[] = array('id' => $x, 'name' => $name, 'image' => $image, 'profilePic' => $profilePic, 'timeStamp' => $timeStamp);
    $x++;
}
echo json_encode(array('feed' => $list));
exit;
}
catch(PDOException $e) {
    echo $e->getMessage();
    exit();
}
?>

php中有更多的代码,但我把它去掉了,因为我认为它不相关,只是查询等。

感谢的帮助

如果使用JsonObjectRequest,则提供param作为JSONObject,而不是getParams(…)

低于,即

JSONObject o = new JSONObject();
o.put("name", regName);
o.put("email", regEmail); 
o.put("password", regPassword1); 
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, url, o,.. );