I'm pretty new to C#, i have this code:
downloads obj = JsonConvert.DeserializeObject<downloads>(data);
foreach (KeyValuePair<string, client> kvp in obj.client)
{
Console.WriteLine("URL: " + kvp.Value.url);
Console.WriteLine("SHA1: " + kvp.Value.sha1);
matrix[0].Add(kvp.Value.url);
matrix[0].Add(kvp.Value.sha1);
}
with these classes:
class downloads
{
[JsonProperty("client")]
public Dictionary<string, client> client { get; set; }
}
class client
{
[JsonProperty("url")]
public string url { get; set; }
[JsonProperty("sha1")]
public string sha1 { get; set; }
}
It says me Object reference not set to an instance of an object but how can i create a reference and use that reference as a type? I mean, i create a reference to downloads this say:
downloads down = new downloads();
but now how can i assign a variable that json deserialize? here is the complete code: https://dotnetfiddle.net/F9mSvQ
Partial JSON:
{
"downloads":
{
"client": { "sha1": "e80d9b3bf5085002218d4be59e668bac718abbc6" },
"server": { "sha1": "952438ac4e01b4d115c5fc38f891710c4941df29" }
}
}