On the web side, it shows how many files and folders I add, but on the c# side, I can’t get the files and folders.
{
"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# Side
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();
}
}
what I’m trying to do is I’m trying to make a tool that will automatically take files and folders as json and check if they are on the computer on the c# side or should they be downloaded and update them.
2
Answers
your equivalent class is wrong here. I have used tool to get the equivalent class.
Item
class should havebyt
property also theRoot
class should haveitems
as the list (in your case you have the object of its type)You will have to fix your jsonFolder class. Replace " object items " with " List< jsonFolder> items " (or " jsonFolder[] items")