使用json_encode方法使用AJAX和PHP获取数据时获取JSON数据

时间:2016-09-10 12:53:04

标签: javascript php json ajax

我使用ajax调用从php获取数据,但数据看起来如下所示。我使用“json_encode”方法获取此数据。我在这里使用ajax调用获取数据。任何人都可以帮我从这个字符串中检索数据。

"[
   {
     "Id":"1",
     "Title":"Image1",
     "Description":"Image1",
     "CreatedDate":"2016-09-05 23:41:42",
     "Order":"1",
     "PhotoUrl":"https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png"
    },
   {
     "Id":"2",
     "Title":"Image2",
     "Description":"Image2",
     "CreatedDate":"2016-09-05 23:41:42",
     "Order":"1",
     "PhotoUrl":"https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png"
    },
   {
     "Id":"3",
     "Title":"Image3",
     "Description":"Image3",
     "CreatedDate":"2016-09-05 23:41:42",
     "Order":"1",
     "PhotoUrl":"https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png"
    },
   {
     "Id":"4",
     "Title":"Image4",
     "Description":"Image4",
     "CreatedDate":"2016-09-05 23:41:42",
     "Order":"1",
     "PhotoUrl":"https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png"
    },
   {
     "Id":"5",
     "Title":"Image5",
     "Description":"Image5",
     "CreatedDate":"2016-09-05 23:41:42",
     "Order":"1",
     "PhotoUrl":"https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png"
    },
]";

我的PHP代码如下:

$resultSet=mysqli_query($connection,"select * from gallery");
$rows=array();
while($r=mysqli_fetch_assoc($resultSet)){
$rows[]=$r;
}
echo json_encode($rows,JSON_UNESCAPED_SLASHES);

谢谢:)

0 个答案:

没有答案