I have a very large Json file (cannot share) Im using https://quicktype.io/csharp/ to generate a C# class from this json file
It gives me a class that looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class Tem
{
[JsonProperty("Cal")]
public Cal Cal_ { get; set; }
}
public partial class Cal
{
[JsonProperty("Cam")]
public Camera[] Cam_ { get; set; }
[JsonProperty("Dis")]
public Dis[] Dis_ { get; set; }
[JsonProperty("Eye")]
public Eye[] Eye_ { get; set; }
[JsonProperty("Ine")]
public Ine[] Ine_ { get; set; }
[JsonProperty("Metadata")]
public Metadata Metadata_ { get; set; }
[JsonProperty("Tem")]
public Tem Tem_ { get; set; }
}
//...There are a lot more
}
Then it has some built internal classes
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
ShutterConverter.Singleton,
AssignedEyeConverter.Singleton,
LocationConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
Not sure what to do with these
I tried to deserialize it this way but it didn't work, all the values were null
using (StreamReader r = new StreamReader(file path))
{
string json = r.ReadToEnd();
QuickType.Cal test = Newtonsoft.Json.JsonConvert.DeserializeObject<QuickType.Cal>(json);
}
I know that the file path is correct and the json string contains the json file. But I dont know how Im supposed to convert from Json.net to this Json generated class
Thanks,
As suggested above by Jeremy Thompson I switched to Json2csharp.com because the formatting is much simpler
Then I parse with
Cal.RootObject test = Newtonsoft.Json.JsonConvert.DeserializeObject<Cal.RootObject>(json);