我收到以下错误:
Error parsing data org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject
这是我拥有的 Android 和 PHP 代码:
private void eventUpdatePoint(String eventStatus,int lat,int lon){
JSONParser jsonParserEUP = new JSONParser();
try
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("longtitude", Integer.toString(lon)));
params.add(new BasicNameValuePair("latitude", Integer.toString(lat)));
params.add(new BasicNameValuePair("eventstatus", eventStatus));
String url_updatePoint = "http://10.0.2.2/android_connect/event_update_point.php";
JSONObject json = jsonParserEUP.makeHttpRequest(url_updatePoint,"POST", params);
Log.d("Response", json.toString());
}
catch(Exception e)
{
e.printStackTrace();
Log.d("ERROR:","ERROR:" + e.getClass().getName() + ":" + e.getMessage());
}
}
php代码:
$response = array(); if (isset($_POST['longtitude']) && isset($_POST['latitude']) &&isset($_POST['eventstatus'])) {
$longtitude = $_POST['longtitude'];
$latitude = $_POST['latitude'];
$eventstatus = $_POST['eventstatus'];
$e_id=0;
$score=0;
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT id FROM cordinates WHERE longtitude=$longtitude AND latitude=$latitude") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$e_id = $row["id"];
}
$result = mysql_query("SELECT score FROM point WHERE e_id=$e_id") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$score = $row["score"];
}
if($eventstatus=="inc")
{
$score+=10;
$result = mysql_query("UPDATE point SET score=$score where e_id=$e_id") or die(mysql_error());
$response["success"] = 1;
$response["message"] ="Score point increased";
}
else if($eventstatus=="dec")
{
$score-=10;
$result = mysql_query("UPDATE point SET score=$score where e_id=$e_id") or die(mysql_error());
$response["success"] = 0;
$response["message"] ="Score point decreased";
}
}
echo json_encode($response);
我究竟做错了什么?