我正在尝试将我的Android应用程序中的一些数据发布到我的Web服务器然后再发送一个值响应,但我一直收到此错误
Error: org.json.JSONException: Value SQLSTATE of type java.lang.String cannot be converted to JSONObject
这是相关的Android代码
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中有更多的代码,但我把它拿出来,因为我不认为它相关,只是查询等...
感谢您的帮助
答案 0 :(得分:1)
如果使用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,.. );