我的Lua應用程序創建一個http:request,以JSON格式獲取響應,將該JSON解碼爲一個表格。好。在Lua中下載文件的最簡單的方法
現在,我能夠提取該JSON文件中的URL。
但是,如何將圖像url保存到Lua中的文件?有沒有圖書館?
編輯:
如何採取JSON文件中的Lua:
json_lib = require('json')
local http = libs.net.http();
local resp = http:request({
method = "get",
url = "http://developer.echonest.com/api/v4/artist/images?api_key=MY_API_KEY_HERE&name=zedd&format=json&results=1&start=0&license=unknown",
});
local json_full = resp.content;
local str_decoded = json_lib.decode(json_full)
function RecursiveSearch(aTable)
for key, value in pairs(aTable) do --unordered search
if(type(value) == "table") then
print(key,value)
RecursiveSearch(value)
else
--Do something with this.
print(key,value)
end
end
end
RecursiveSearch(str_decoded)
我的JSON的反應是:
{
"response":{
"status":{
"version":"4.2",
"code":0,
"message":"Success"
},
"start":0,
"total":20,
"images":[
{
"url":"http://userserve-ak.last.fm/serve/_/67419844/ZEDD.png",
"license":{
"type":"unknown",
"attribution":"n/a",
"url":"http://www.last.fm/music/ZEDD/+images"
}
}
]
}
}
所以我想在磁盤上保存的第一網址藝術家的照片。
你是說保存實際圖像本身還是隻保存url文本鏈接? – greatwolf
我想保存圖像本身。我已經完成的url文本。感謝您的關注。 – MatheusLPS
您必須已經使用庫來獲取json文檔,否?不只是使用它來下載圖像文件的工作? –