帮助需要的朋友,我想将从数据库检索到的图像信息转换为json格式。 下面是从数据库将图像信息从服务器转换为json
// Query for a list of all existing files
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
$result = $dbLink->query($sql);
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<table width="100%">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b> </b></td>
</tr>';
// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
</tr>";
}
// Close table
echo '</table>';
}
// Free the result
$result->free();
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
这里获取图像信息的代码是什么想实现
{
"success": 1,
"message": "images Available",
"images": [
{
"Name": "richmahnn",
"Mime": "ajh544k",
"Size": "222",
"Created": "232014",
"url": "http://localhost/imageUpload/ajh544k.jpg"
},
{
"Name": "john",
"Mime": "ajh5644k",
"Size": "15",
"Created": "232014",
"url": "http://localhost/imageUpload/ajh5644k.jpg"
},
到目前为止,这是我所得到的
你有没有尝试过任何的JSON转换?如果是这样,请显示你的尝试和具体出错。 PHP的['json_encode()'](http://php.net/manual/en/function.json-encode.php)可能会有帮助。 – showdev 2015-01-09 18:46:46
你试过json_encode() 查http://php.net/manual/en/function.json-encode.php – 2015-01-09 18:48:11