在web端,它显示了我添加了多少文件和文件夹,但是在c#端,我无法获得这些文件和文件夹。
{
"name": "updater",
"type": "folder",
"path": "updater",
"items": [
{
"name": "tas",
"type": "folder",
"path": "updater/tas",
"items": [
{
"name": "sdsadsd.txt",
"type": "file",
"path": "updater/tas/sdsadsd.txt",
"byte": 6
},
{
"name": "tass",
"type": "folder",
"path": "updater/tas/tass",
"items": []
},
{
"name": "trexs.txt",
"type": "file",
"path": "updater/tas/trexs.txt",
"byte": 14
}
]
},
{
"name": "tas2",
"type": "folder",
"path": "updater/tas2",
"items": []
},
{
"name": "tas3",
"type": "folder",
"path": "updater/tas3",
"items": []
},
{
"name": "tas4",
"type": "folder",
"path": "updater/tas4",
"items": []
}
]
}
C#侧
public class jsonFF
{
public string name { get; set; }
public string type { get; set; }
public string path { get; set; }
public jsonFF[] items { get; set; }
public long byt { get; set; }
}
private void start_Click(object sender, EventArgs e)
{
try
{
WebClient updt = new WebClient();
var updtJsonDownload = updt.DownloadString("http://localhost/update/updater.php");
jsonFF[] json = JsonConvert.DeserializeObject<jsonFF[]>(updtJsonDownload.ToString());
foreach (var item in json)
{
string sss = item.name;
log.Text += sss + Environment.NewLine;
}
}
catch (Exception ex)
{
log.Text = ex.ToString();
}
}
我想做的是我想做一个工具,它能自动把文件和文件夹当作json,检查它们是否在c#端的计算机上,或者应该下载并更新它们。
2条答案
按热度按时间unguejic1#
你的等价类在这里是错误的。我已经使用tool来得到等价类。
Item
类应该有byt
属性同样Root
类应该有items
作为列表(在你的例子中你有它的类型的对象)58wvjzkj2#
您必须修复jsonFolder类。将“对象项“替换为“列表< jsonFolder>项“(或“jsonFolder[]项”)