I managed to find a solution without removing the paths from the keys.
Thanks for helping the guys and also pointing out the problems, I really appreciate it! :)
I loaded Json into a string, deserialized it into a dynamic one, passed a profile through it, and added it to the list with ResFiles in it.
static void loadJson() { List<ResFile> fileList = new List<ResFile>(); string jsonString = File.ReadAllText(jsonPath); dynamic files = JsonConvert.DeserializeObject(jsonString); foreach (var f in files.objects) fileList.Add(new ResFile(f.Name, f.Value.hash.ToString(), (int)f.Value.size.Value)); }
I am trying to deserialize some Json file in C # using the Newtonsoft Json library.
The files are named after the hash, not the name of the real file, and I want to rename them to names that should be specified as follows: 10a54fc66c8f479bb65c8d39c3b62265ac82e742 → file_1.ext
Json File:
{ "files": { "file_1.ext": { "hash": "10a54fc66c8f479bb65c8d39c3b62265ac82e742", "size": 8112 }, "file_2.ext": { "hash": "14cfb2f24e7d91dbc22a2a0e3b880d9829320243", "size": 7347 }, "file_3.ext": { "hash": "bf7fadaf64945f6b31c803d086ac6a652aabef9b", "size": 3838 }, "file_4.ext": { "hash": "48f7e1bb098abd36b9760cca27b9d4391a23de26", "size": 6905 } } }
I tried to deserialize with this:
static void loadJson() { using (StreamReader reader = new StreamReader(jsonPath)) { string json = reader.ReadToEnd(); dynamic files = JsonConvert.DeserializeObject(json); } }
Deserialization itself works, but I don't know how to skip it.
I also tried to do this:
class ResFile { public string name; public string hash; public int size; }
And somehow make deserialization use this, but that didn't work, of course.