aardio
import win.ui;
import web.json;
import inet.http;
import fsys;
/*DSG{{*/
var winform = win.form(text="Aardio 示例";right=600;bottom=400)
winform.add(
button1={cls="plus";text="生成JSON并保存";left=30;top=30;right=230;bottom=70;bgcolor=0xFF4F81BD;color=0xFFFFFFFF;font=LOGFONT(name='微软雅黑';h=-16);z=1};
button2={cls="plus";text="获取网页内容";left=30;top=90;right=230;bottom=130;bgcolor=0xFF9BBB59;color=0xFFFFFFFF;font=LOGFONT(name='微软雅黑';h=-16);z=2};
edit={cls="edit";left=30;top=160;right=570;bottom=370;edge=1;multiline=1;vscroll=1;z=3}
)
/*}}*/
// 按钮1点击事件 - 生成JSON并保存
winform.button1.oncommand = function(id,event){
// 创建从221到12的数组
var arr = {};
for(i=221; i>=12; --i){
table.push(arr, i);
}
// 转换为JSON
var jsonStr = web.json.stringify(arr, null, 2);
// 显示在文本框中
winform.edit.text = jsonStr;
// 保存到文件
var filePath = fsys.joinpath(io._exedir, "output.json");
if(fsys.exists(filePath)){
fsys.remove(filePath);
}
var file = fsys.file(filePath, "w");
file.write(jsonStr);
file.close();
winform.msgbox("JSON已保存到: " + filePath, "提示");
}
// 按钮2点击事件 - 获取网页内容
winform.button2.oncommand = function(id,event){
var http = inet.http();
try {
// 获取网页内容
var html = http.get("https://www.example.com");
// 简单示例:提取<title>标签内容
var titleStart = string.find(html, "<title>");
var titleEnd = string.find(html, "</title>");
if(titleStart && titleEnd){
var title = string.slice(html, titleStart + 7, titleEnd - 1);
winform.edit.text = "网页标题: " + title;
} else {
winform.edit.text = "未找到标题标签\n网页前200字符:\n" + string.slice(html, 1, 200);
}
} catch(e) {
winform.edit.text = "请求失败: " + tostring(e);
}
}
winform.show();
win.loopMessage();