I have a question about JSON.NET and deserializing nested JSON.
I was wondering if I could extract some properties out of an API response without making a class to store the parent object using JsonConvert.DeserializeObject.
Example JSON:
{
"data": [
{
"type": "player",
"id": "account.59daecb0cc3144f7bf6e60c8caabf454",
"attributes": {
"createdAt": "2018-04-03T21:11:16Z",
"name": "UppyMeister",
"patchVersion": "",
}
}]
}
Example Class:
public class Player
{
[JsonProperty]
public string Name { get; set; }
[JsonProperty]
public DateTime CreatedAt { get; set; }
[JsonProperty]
public string PatchVersion { get; set; }
}
So far, I haven't found a way to make this work. Obviously I've tried making a seperate class called "Attributes" that store these properties, and then keeping player as the root object, which of course works, but I was wondering if there's any way to make this work without having to make multiple classes to represents all the objects while still using JsonConvert.DeserializeObject<IEnumerable<Player>>(json);
Thanks
EDIT: Forgot to mention that It's not as easy as just parsing the json string into a json object and then instead deserializing json["data"][0]["attributes"]
as I need to store other properties in the class, such as "type" and "id" in this example.