I have this simply follow json and class that I want to DeserializeObject to object.
{\"UnsubscribeResponse\": {
\"txId\": \"123\",
\"result\": \"Success\"
Add a new class:
public class UnsubscribeResponsewrapper
{
public UnsubscribeResponse UnsubscribeResponse { get; set; }
}
and then rather than reading / deserialising as UnsubscribeResponse
, use UnsubscribeResponseWrapper
instead. This is necessary since your JSON is:
{"UnsubscribeResponse": {
"txId": "123",
"result": "Success",
"message": "OK"
}}
For your original code to work, the JSON would need to be something like:
{
"txId": "123",
"result": "Success",
"message": "OK"
}
You need the extra class since your JSON has the UnsubscribeResponse
property. I suspect you are looking at your JSON and thinking this is a UnsubscribeResponse
object and its properties. But that isn't actually what your JSON is. It is this is an object, with a UnsubscribeResponse
property (and that property has a set of its own properties). As such, you need to either alter the JSON (as per my altered JSON) or alter the code (as per my class).