現在,我有我的JSON從選擇創建從MySQL,看起來像這樣:改變我的JSON字符串在一個循環
$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
更改爲我可以使用的編碼。
好像在您通過數據的第一次迭代期間檢查它會是最簡單的。如果行鍵eq圖像然後運行您的正則表達式的值。也許在最後/如果所有圖像路徑被格式化後都會返回所有內容 –
問題是什麼?你不知道如何打開一個文件並閱讀它? – daxim
@daxim我這樣做,但我不知道如何在$ jsonData中訪問它。我將如何循環訪問每個圖片的ref? – BluGeni