编码为json时php脚本出错

I have currently a php script as given below:

<?php 
$con=mysqli_connect("localhost","username","password","temp"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}
$username = mysqli_real_escape_string($con, $_POST['username']); 
$result = mysqli_query($con,"SELECT imagename FROM table3 where username='$username'");

$rows = array();
while($r = mysqli_fetch_assoc($result)) 
{
    $rows[] = $r;
}
echo json_encode($rows);

mysqli_close($con);
?>

The output which I get after running this script is in the form given below:

[{"imagename":"1"},{"imagename":"2"}]

But I need a string in a format like this as my output:

{"Android":[{"imagename":"1"},{"imagename":"2"}]}.

That is, I should be able to add the string {"Android": to the beginning of my actual output and add the string } to the ending part of my actual output.

So what code should I need to add extra to obtain like the above format. Can someone please help me out.. Thanks in advance..

try this by defining your key in the array of $rows you should get your result you want.

{
$rows['Android'] = $r;
}