0
這不是工作(該文件存在,它讀取就OK了,那麼沒有環火),我不知道爲什麼..C#JSON讀不會發生
if (File.Exists("my.json"))
{
var response = System.IO.File.ReadAllText("my.json");
var domains = JsonConvert.DeserializeObject<List<jsonRead>>(response);
foreach (jsonRead domain in domains)
{
MessageBox.Show(domain.Password);
var folders = JsonConvert.DeserializeObject<List<jsonReadDeep>>(domain.Folders);
foreach (jsonReadDeep folder in folders)
{
MessageBox.Show(folder.localServer);
}
}
}
類
class jsonRead
{
public string Folders;
public string Name;
public string User;
public string Password;
public string Url;
}
class jsonReadDeep
{
public string localFolder;
public string serverFolder;
}
的JSON
[
{
"Folders": [
{
"localFolder": "C:\\test",
"serverFolder": "Default/"
}
],
"Name": "hi",
"User": "there",
"Password": "secret",
"Url": "https://mydomain.com"
}
]
這是確定它是簡單://公共ArrayList的文件夾//在jsonRead - 我會假設JSON會腐爛,並通過它作爲一個字符串 - 但很明顯不是; – conners