现在我有我的 json,它是从 mysql 中选择创建的,看起来像这样:
$sth->execute()
or die "SQL Error: $DBI::errstr\n";
while (my $row = $sth->fetchrow_hashref ){
push @output, $row;
# print $row->{image};
$photo = $row->{image};
my $file = "$photo";
my $document = do {
local $/ = undef;
open my $fh, "<", $file
or die "could not open $file: $!";
<$fh>;
};
my $encoded= MIME::Base64::encode_base64($document);
}
JSON看起来像这样:
{"myData":[{"favorited":null,"date":"2013-07-31","preferredMeetingLocation":"meet here","description":"Clothes desc","image":"/var/www/pictures/photo-7h1sIsXQ.jpg","id":"31","title":"clothing ","price":"12","category":"Clothing","isbn":null}]}
我想要做的是代替它显示图像的文件路径的位置,我想将其更改为 json 字符串中每个对象的实际图像。最终我想将每个图像编码为base64,但我知道如何做那部分。在这种情况下,我只需要帮助更改/var/www/pictures/photo-7h1sIsXQ.jpg
为我可以使用和编码的东西。