2012-08-06 162 views
0

我是Android開發新手。我將Android的JSON數據發送到我的PHP服務器。但我發現了一個錯誤:解析JSON時出錯

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))); 

?> 
+0

我打印了我的php代碼以供參考。 – Rohit13 2012-08-06 04:41:37

回答

0

聽起來像是你有一些HTML嵌入,可能是一個PHP錯誤/警告字符串。來自服務器的響應必須包含僅限的json數據。其他任何東西都會成爲字符串的一部分並導致解析錯誤。

以您在android中擊中的確切網址並查看它在瀏覽器中顯示的內容爲準。