You have a couple of possibilities (as already showed in the other answers). Another possibility would be to use the JObject
and JProperty
properties provided from Json.Net, in order to directly fetch the value like this:
var jsonObject = (JObject)JsonConvert.DeserializeObject(json);
var unashamedohio = (JObject)(jsonObject.Property("unashamedohio").Value);
var summonerLevel = unashamedohio.Property("summonerLevel");
Console.WriteLine(summonerLevel.Value);
Yet another possibility would be to create a typed model of the JSON structure:
public class AnonymousClass
{
public UnashamedOhio unashamedohio { get; set; }
}
public class UnashamedOhio
{
public int summonerLevel { get; set; }
}
and use it to retrieve the value:
var ao = JsonConvert.DeserializeObject<AnonymousClass>(json);
Console.WriteLine(ao.unashamedohio.summonerLevel);
Both solutions print the same value: 30
.
IMO you should use always typed models when possible and if you do a lot of value fetching from a JSON structures. It provides error checking in the IDE (as opposed to dynamic) which pay-offs at runtime.