运行一个简单的搜索查询,它提供给android studio textview。当我第一次设法通过.php站点显示结果时,所有特殊字符([{]})都显示出来了,但是我添加了这一行来删除:
echo json_encode($resultArray, DEFINED('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0);
然而,这现在意味着显示的结果也缺少特殊字符,主要是""。所以"You’re"实际上显示的是"You’re"
我试着玩上面的json查询,但没有运气-知道我做错了什么吗?
完整代码:
<?php
// Create connection
$con=mysqli_connect("server","user","pass","table");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Select all of our stocks from table 'stock_tracker'
$sql = "
SELECT Task_title
, task_description
FROM TASKS
ORDER
BY RAND () ASC
LIMIT 1
";
// Confirm there are results
if ($result = mysqli_query($con, $sql))
{
// We have results, create an array to hold the results
// and an array to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each result
while($row = $result->fetch_object())
{
// Add each result into the results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Encode the array to JSON and output the results
echo json_encode($resultArray, DEFINED('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0);
echo json_last_error_msg(); // Print out the error if any
die(); // halt the script
}
// Close connections
mysqli_close($con);
?>
我通过在搜索查询下面添加$cValue=str_replace(array("'",",","."), array("&#039;","&#44;","&#46;"), $_POST['contractValue']);
来解决这个问题。真管用!