I see many simple examples of JSON DeSerialization, but when it comes to something more complex, there is a lack of samples.
I am looking for deserialization of responses from the GetResponse API:
Simple for example
{
"result" : {
"updated" : "1"
},
"error" : null
}
Other:
{
"result" : null,
"error" : "Missing campaign"
}
Here's another more complex potential answer:
{
"result" : {
"CAMPAIGN_ID" : { // <-- This value will be different for each Campaign
"name" : "my_campaign_1",
"from_name" : "My From Name",
"from_email" : "me@emailaddress.com",
"reply_to_email" : "replies@emailaddress.com",
"created_on" : "2010-01-01 00:00:00"
}
},
"error" : null
}
For this last one, what should my object look like?
At first I played with something like this ...
private struct GenericResult {
public string error;
public Dictionary<string, object> result;
}
This will work for all my reponses, but then to access the properties of the object, which I will have to use if I am not mistaken.
I want to use it as follows:
JavaScriptSerializer jss = new JavaScriptSerializer();
var r = jss.Deserialize<GenericResult>(response_string);
var r = jss.Deserialize<GetCampaignResult>(response_string);
EDIT
After returning the data, the actual structure has one coupling device. Here is an example:
Value
{
"error":null,
"result":
{"ABQz": { // <-- As you can see, this is NOT a class name.
"from_email" : "from@email.com",
"created_on" : "2010-10-15 12:40:00",
"name" : "test_new_subscribers",
"from_name" : "John Smith",
"reply_to_email": "from@email.com"
}
}
}
Now that I do not know what this value will be, I am at a standstill. I would like to include this value as an identifier for the object Campaign.