在Offline.json
中设置文件目录
您能否告诉我如何在现有的JSON文件上编写
{
"GDB":[ "C:Data/GDB/GDB1.gdb",
"C:Data/GDB/GDB2.gdb",
"C:Data/GDB/GDB3.gdb"
],
"TPK":[ "C:Data/TPK/TPK1.gdb",
"C:Data/TPK/TPK2.gdb"
],
"MPK":[ "C:Data/MPK/MPK1.mpk",
"C:Data/MPK/MPK2.mpk",
"C:Data/MPK/MPK3.mpk",
"C:Data/MPK/MPK4.mpk",
"C:Data/MPK/MPK5.mpk",
"C:Data/MPK/MPK6.mpk"
]
}
就像
unsigned long
加载WPF主窗口?
答案 0 :(得分:1)
使用Newtonsoft Json.NET这很容易实现:
// Your main code...
String path = @"C:\Data\";
DirectoryInfo di = new DirectoryInfo(path);
String json = GetJsonDirectoryStructure(di).ToString();
// Method implementation...
public static JObject GetJsonDirectoryStructure(DirectoryInfo di)
{
JObject jObj = new JObject();
foreach (DirectoryInfo diChild in di.GetDirectories())
jObj.Add(diChild.Name, GetJsonDirectoryStructure(diChild));
foreach (FileInfo di in di.GetFiles())
jObj.Add(fi.Name, JValue.CreateNull());
return jObj;
}