VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • 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));


相关教程