Php 将mysql查询简介转换为json对象

Php 将mysql查询简介转换为json对象,php,mysql,json,Php,Mysql,Json,这是我的代码: $eventList = array(); while($rows = mysql_fetch_array($produse)){ $url = $http_location . '/' . str_replace(' ', '-', $rows['title']) . '.html' ; $image = ($rows['image_path'][0] == "." ? $http_location.substr($rows['image_path'], 1) :

这是我的代码:

$eventList = array();

while($rows = mysql_fetch_array($produse)){

$url   = $http_location . '/' . str_replace(' ', '-', $rows['title']) . '.html' ;   
$image = ($rows['image_path'][0] == "." ? $http_location.substr($rows['image_path'], 1) : $r['image_path']);

$eventList[] = array(
    //'id' => $rows['productid'],
    'Title' => $rows['productname'],
    'Description' => $rows['description'],
    'Short message' => '',
    'Price' => $rows['price'],
    'Category' => $rows['category'],
    'Subcategory' => '',
    'URL' => $url,
    'Image' => $image,
    'Product ID' => $rows['productid'],
    'Generate link text' => 0,
    'Brand' => $rows['manufacturer'],
    'Active' => 1,
    'Other data' => ''
);

unset($url, $image);
}


// print '<pre>';
// print_r($eventList);

//header('Content-Type: application/json');

$eventList = json_encode($eventList);

echo json_encode($eventList);

mysql_close(); 
$eventList=array();
而($rows=mysql\u fetch\u数组($produse)){
$url=$http_location.'/'.str_replace(''''.-',$rows['title'])。.html';
$image=($rows['image\u path'][0]=“?$http\u location.substr($rows['image\u path'],1):$r['image\u path']);
$eventList[]=数组(
//'id'=>$rows['productid'],
'Title'=>$rows['productname'],
'Description'=>$rows['Description'],
'短消息'=>'',
“价格”=>$rows[“价格”],
'Category'=>$rows['Category'],
“子类别”=>“”,
“URL”=>$URL,
“Image”=>$Image,
'Product ID'=>$rows['productid'],
“生成链接文本”=>0,
“品牌”=>$rows[“制造商”],
“活动”=>1,
“其他数据”=>“
);
取消设置($url,$image);
}
//打印“”;
//打印(事件列表);
//标题('Content-Type:application/json');
$eventList=json_encode($eventList);
echo json_encode($eventList);
mysql_close();
这是查询的结果:

“[{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\价格:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\类别:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\URL\“:\”http:\/\/www.fabricademagie.ro\/Costum buburuza copii fete.html\”,“Image\:\”http:\/\/www.fabricademagie.ro\/images\/P\/63442-01.jpg\”,“产品ID\”:“5\”,“生成链接文本”:0,““品牌\”:null,““活动\”:1,\“其他数据\:”:“,“,“,”,“{”标题:“:“Costum buburuza\”,“说明:”Costum buburuza copii pentru fete,包括罗夏莱卡啤酒、实用弗洛尔、fuste din缎面装饰、曼尼奇detasabile、aripi si Cordeleta cu antenute.,“短消息”:“,”价格“:”114.00“,”类别“:”服装狂欢节“,”子类别“:”,”URL“:”http:\/\/www.fabricademagie.ro\/Costum buburuza copii fete.html\',“Image\:\”http:\/\/www.fabricademagie.ro\/images\/P\/63442-01.jpg\',“产品ID\”:“5\”,“生成链接文本\”:0,\“品牌\:null,\“活动\\”:1,\“其他数据\\”:“\”

我做错了什么,我收到的是这种类型的结果,而不是标准的json对象

$eventList = json_encode($eventList);
echo $eventList;
您对字符串进行了两次编码

$eventList = json_encode($eventList);

echo $eventList;

多田;)

尝试删除一个json_编码:

echo json_encode($eventList);


从代码中删除第二个json_encode()函数。应该是这样的:

echo json_encode($eventList);
或者,如上所述:

将所有mysql()函数替换为mysqli或PDO或使用它们的库也是明智的

$eventList = json_encode($eventList);
echo $eventList;
echo json_encode($eventList);