然后我们双击“获取纯净版列表”按钮,在button4_click()中键入代码:
if (File.Exists(Application.StartupPath + "\\tmp.json"))//如果临时文件存在
{
File.Delete(Application.StartupPath + "\\tmp.json");//删掉
}
wc.DownloadFile("
https://launchermeta.mojang.com/mc/game/version_manifest.json", Application.StartupPath + "\\tmp.json");//下载版本列表文件
String rtxt = File.ReadAllText(Application.StartupPath + "\\tmp.json").Replace("\n", "").Replace(" ", "");//读取版本列表
File.Delete(Application.StartupPath + "\\tmp.json");//删除临时文件
int tmp = rtxt.IndexOf("versions") + "versions".Length + 3;//读取objects数组数据
String versions_S = rtxt.Substring(tmp, rtxt.LastIndexOf("]", rtxt.Length - 1) - tmp);//同上
String[] versions = versions_S.Replace("},{", "$").Split("$".ToCharArray());//分割数组
String tmu = "";//声明并初始化tmu
listBox1.Items.Clear();//清空列表
foreach (String vi in versions)
{//为每个项循环
tmp = vi.IndexOf("id") + "id".Length + 3;//读取id
tmu = vi.Substring(tmp, vi.IndexOf("\"", tmp) - tmp);//同上
tmp = vi.IndexOf("url") + "url".Length + 3;//读取url
String tmua = vi.Substring(tmp, vi.IndexOf("\"", tmp) - tmp);//同上
listBox1.Items.Add(tmu + " " + tmua);//添加项
}