Я пытаюсь десериализовать файлы json с помощью newtonsoft.json в C#
Файлы json похожи на текст ниже.
{ "lmod_file": { "crlmod": true, "name": "corn silage;Ffcult with disked radish cover, z4", "params": { "param": [ { "data": [ { "file_key": null }, { "file_key": "999", "value": "vegetations\\Corn, silage" }, { "file_key": null }, { "file_key": null }, { "file_key": "999", "value": "vegetations\\Brassica, cover, forage, release" } ], "name": "VEG_PTR" }, { "data": [ { "file_key": "999", "value": "operations\\Cultivator, field 6-12 in sweeps" }, { "file_key": "999", "value": "operations\\Planter, double disk opnr, 40 in rows" }, { "file_key": "999", "value": "operations\\Harvest, silage" }, { "file_key": "999", "value": "operations\\Disk, tandem light finishing" }, { "file_key": "999", "value": "operations\\Drill or air seeder, double disk" } ], "name": "OP_PTR" }, { "data": [ "0001-04-28", "0001-05-01", "0001-09-15", "0001-09-16", "0001-09-17" ], "name": "OP_DATE" }, { "data": [ "NULL", "23", "NULL", "NULL", "1500" ], "name": "MAN_OP_VEG_NUM_HARV_UNITS" }, { "data": [ { "file_key": null }, { "file_key": null }, { "file_key": null }, { "file_key": null }, { "file_key": null } ], "name": "EXT_RES_PTR" }, { "data": [ "NULL", "NULL", "NULL", "NULL", "NULL" ], "name": "RES_ADDED" }, { "data": true, "name": "WEPP_NAMES", "type": "Bool", "value": "true" } ] }, "path": "managements\\CMZ 04\\a.Single Year/Single Crop Templates\\Corn silage" } }
Что я уже пробовал:
Models.JsonLmodFileClass.LmodFileClass lmodObj = JsonConvert.DeserializeObject<Models.JsonLmodFileClass.LmodFileClass>(text);
классы, определенные ниже:
public class JsonLmodFileClass { public class LmodFileClass { public class Rootobject { public Lmod_File lmod_file { get; set; } public Rootobject() { lmod_file = new Lmod_File(); } } public class Lmod_File { public bool crlmod { get; set; } public string name { get; set; } public Params _params { get; set; } public string path { get; set; } public Lmod_File() { _params = new Params(); } } public class Params { public Param[] param { get; set; } public Params() { param = new Param[1]; } } public class Param1 { public object data { get; set; } public string name { get; set; } public string type { get; set; } public string value { get; set; } } public class TJsonArrayOfStr { public string name { get; set; } public List<string> values { get; set; } public TJsonArrayOfStr() { values = new List<string>(); } } public class TJsonArrayOfKeyValues { public string name { get; set; } public List<TJsonFileKeyValue> values { get; set; } public TJsonArrayOfKeyValues() { values = new List<TJsonFileKeyValue>(); } } public class Param { public TJsonArrayOfKeyValues vegPtr; //Array file_key - value public TJsonArrayOfKeyValues opPtr; //Array file_key - value public TJsonArrayOfStr opDate; //Array of string values public TJsonArrayOfStr manOpVegHarvest; //Array of string values public TJsonArrayOfKeyValues exRes; //Array file_key - value public TJsonArrayOfStr resAdded; //Array of string values public Param() { vegPtr = new TJsonArrayOfKeyValues(); vegPtr.name = "VEG_PTR"; opPtr = new TJsonArrayOfKeyValues(); opPtr.name = "OP_PTR"; opDate = new TJsonArrayOfStr(); opDate.name = "OP_DATE"; manOpVegHarvest = new TJsonArrayOfStr(); manOpVegHarvest.name = "MAN_OP_VEG_NUM_HARV_UNITS"; exRes = new TJsonArrayOfKeyValues(); exRes.name = "EXT_RES_PTR"; resAdded = new TJsonArrayOfStr(); resAdded.name = "RES_ADDED"; } } } }