C# 读取.resx资源文件写入到json文件中

//调用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));

 

posted @ 2020-04-27 13:55  Smile灬Lucky  阅读(907)  评论(0编辑  收藏  举报