我正在通过
PHP托管JSON输出的Web服务.
我在DB中有希伯来语数据集,我将此作为输出发布到Web服务.
当我最初发布数据时,它输出结果如下:
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ×רמה ×™×–×•× ×•×‘×™× ×•×™ בע"מ",
"cargo":"×ברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
但是这个“×הרר“可以被Android / Iphone解析器读取并将其转换为原始的希伯来语.但我在“名字”中遇到错误:“×〜ר××¨×ž×”×™× – ו×וגי×ויגע“מ”,其中“位于字符串之间,因此JSON无效并显示错误!
为了解决这个问题我使用UTF-8将“×גרר”转换为希伯来语“נברר”.但在这种情况下,问题仍然存在:
PHP:
header(‘Content-type: text/html; charset=UTF-8’);
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ארמה יזום ובינוי בע"מ",
"cargo":"נברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
但问题仍然存在:
在某些情况下,由于使用UTF-8,我得到了这个
"name":"מחצבות כפר גלעדי-חומרי מ�"
>我如何克服这个问题?
>我需要使用其他特定编码吗?
注意:数据不能在数据库中更改解决方案应该在输出到JSON时.
DB中存储的数据如何显示如下:
name
מחצבות כפר גלעדי-חומרי מ×
我的PHP脚本输出JSON:
//My DB connection and Query comes here
$jsontext = '{"tasklist":[';
while($row = mysql_fetch_array($queryExe)){
$jsontext .= '{"customerID":"'.$row['AUTO_ID'].'",';
$jsontext .='"name":"'.$row['Customer_Name'].'",';
$jsontext .='"cargo":"'.$row['Type_of_Cargo'].'",';
$jsontext .='"destination":"'.$row['Destination'].'",';
$jsontext .='"quantity":"'.$row['Quantity'].'",';
$jsontext .='"startdate":"'.$row['startdate'].'"},';
}
$jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
$jsontext .= "]}";
header('Content-type: text/html; charset=UTF-8');
//Output the final JSON
echo $jsontext;
?>
提前谢谢你的帮助!
问题清楚了吗?了解我的问题.