I'm having trouble figuring out how to parse a JSON object with anonymous objects. Here is my JSON:
{
"success": true,
"affectedRows": 2,
"data": [
{
"success": true,
"affectedRows": 1,
"data": [
{
"ID": 376,
"SomeOtherID": 0,
"StringValue": "Fan"
}
]
},
{
"success": true,
"affectedRows": 1,
"data": []
},
{
"success": true,
"data": {
"ID": 401,
"DateTime": "2014-10-03 18:52:48"
}
}
]
}
I have a class that contains classes that work as models for the JSON response I'm expecting.
public class JSONObjects
{
public class Success
{
public bool success {get;set}
public int affectedRows {get;set;}
}
public class Response
{
public int ID {get;set;}
public int SomeOtherID {get;set;}
public string StringValue {get;set;}
}
public class FirstResponse : Success
{
public Response[] data {get;set;}
}
public class SecondResponse : Success
{
public object[] data {get;set;}
}
public class TimeData
{
public int ID {get;set;}
public string DateTime {get;set;}
}
public class FullTimeData
{
public bool success {get;set;}
public TimeData data {get;set;}
}
public class FullResponse : Success
{
// ??? anonymous object[] data ???
}
}
usage:
FullResponse data = JsonConvert.DeserializeObject<JSONObjects.FullResponse>(jsonString, jsonSerializerSettings);
Debug.WriteLine(data.data[0].anonymousObject0.data[0].StringValue);
How can I place the anonymous objects in the FullResponse class as an array of objects and then later access them?