I have some JSON that looks like this:
{
"data": {
"storePurchase": {
"id": "d4f7475a-0023-416f-b6a1-257659a341f5",
}
}
}
I also have some JSON that looks like this:
{
"data": {
"userInfo": {
"username": "...."
}
}
}
How can I write a deserializer to handle any object type that might appear under data
. I know the structure of the sub-objects under data upfront, so I don't need dynamics.
I have tried this so far:
public class BaseData<T>
{
public T Data { get; set; }
}
[JsonObject("userInfo")]
public class Me
{
[JsonProperty("username")]
public string Username { get; set; }
}
public class BootstrapQueryResponse
{
[JsonProperty("data")]
public BaseData<Me> BaseData { get; set; }
}
[TestMethod]
public void Test()
{
string json = @"{
""data"": {
""userInfo"": {
""username"": ""....""
}
}
}";
BootstrapQueryResponse s = JsonConvert.DeserializeObject<BootstrapQueryResponse>(json);
}
However, my object s
is returning null
for the data
property.