0

我是 Android 开发的新手。我正在将 JSON 数据从 Android 发送到我的 PHP 服务器。但我收到一个错误:

Error parsing data org.json.JSONException: Value `<br` of type java.lang.String cannot be converted to JSONObject".

这是我的 PHP 代码:

<?php

$con = mysql_connect("localhost","custome234r","reswtdf123");
if (!$con)
    die('Could not connect: ' . mysql_error());
mysql_select_db("customer_dd_test", $con);

$jsonFeedbackResult = $_REQUEST['results'];

$flagToOpenTicket = false;            

$arrResult = json_decode(stripslashes_deep($jsonFeedbackResult));

$feedbackname = $arrResult[0]['feedbackname'];
$email = $arrResult[0]['email'];

unset($arrResult[0]);
$finalArray = array_values($arrResult);
foreach($finalArray as $key => $arrQuestionWithAnswer)
{
    if($arrQuestionWithAnswer['answer'] == 'bad' || $arrQuestionWithAnswer['answer'] == 'worst')
    {
        $flagToOpenTicket = true;
        break;
    }
}

if($flagToOpenTicket)
{
    $insertQuery = 'INSERT INTO dev_ticket(email, feedbackname) VALUES'; 
    $insertQuery .= '("'.$email.'", "'.$feedbackname.'"),';
    $executeQuery = trim($insertQuery,',');
    mysql_query($executeQuery);

}
mysql_close($con);
print(json_encode(array('response'=>$feedbackname)));

?>
4

1 回答 1

0

听起来您嵌入了一些 HTML,可能是 PHP 错误/警告字符串。来自服务器的响应必须包含 json 数据。其他任何内容都将成为字符串的一部分并导致解析错误。

获取您在 android 中点击的确切 url,然后查看它在浏览器中显示的内容。

于 2012-08-06T04:34:42.803 回答