C# 读取.resx资源文件写入到json文件中
程序员文章站
2022-03-08 13:13:03
//调用ResXResourceReader类,需要引用System.Windows.Forms.dll,下同 ResXResourceReader resxReader = new ResXResourceReader(@"资源文件路径"); IDictionaryEnumerator dict ......
//调用resxresourcereader类,需要引用system.windows.forms.dll,下同
resxresourcereader resxreader = new resxresourcereader(@"资源文件路径");
idictionaryenumerator dict = resxreader.getenumerator();
stringbuilder jsonbuilder = new stringbuilder("{\"th_th\": {");
while (dict.movenext())
{
console.writeline("{0},{1}", dict.key, dict.value);
jsonbuilder.append("\"" + dict.key + "\":\"" + dict.value + "\",\n");
}
var jsonstring = jsonbuilder.tostring().substring(0, jsonbuilder.length - 2) + "}}";
var path = directory.getcurrentdirectory();
file.writealltext(path + "/th_th.json", regex.unescape(jsonstring));