צפיות
תשובות
יצירת אובייקט json בעברית
שלום,
כתבתי קובץ php שמייצר אובייקט json באופן הבא:
<html>
<head>
<meta charset=utf-8" />
</head>
<body>
<?php
header('Content-Type: text/html; charset=utf-8');
$response = array();
require_once __DIR__.'/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query(" SELECT * FROM stores") or die(mysql_error());
if (mysql_num_rows($result)>0){
$response["stores"]=array();
while($row = mysql_fetch_array($result)){
$store = array();
$store["_id"]=$row["_id"];
$store["name"]=$row["name"];
$store["store_type"]=$row["store_type"];
array_push($response["stores"],$store);
}
$response["success"] = 1;
$string = utf8_encode(json_encode($response));
echo hebrevc($string);
}else{
$response["success"]=0;
$response["message"]="No stores found";
echo utf8_encode(json_encode($response));
}
?>
</body>
</html>
|
האובייקט שאני מקבל נראה כך:
{{"stores":[{"_id":"1","name":"u05d7u05eau05d5u05dcu05d9","store_type":"u05deu05e1u05e2u05d3u05ea u05d1u05e9u05e8u05d9u05dd"},{"_id":"2","name":"u05deu05e2u05d3u05e0u05d9 u05deu05d0u05deu05d9","store_type":"u05deu05e1u05e2u05d3u05d4 u05dcu05e8u05d5u05e1u05d9u05dd"}],"success":1
כיצד ניתן לוודא שיוצג בעברית על ה-browser של ה client?
1 תשובות
בדוק את התוצאה באצלך בדפדפן באמצעות JSON.parse(), לדוגמא: JSON.parse('{"name":"u05d7u05eau05d5u05dcu05d9"}');
נתן לי את התוצאה "חתולי"
אפשרות שנייה השתמש ב-http://jsonlint.com/