There is another approach: you can use expando objects :
dynamic response = JsonConvert.DeserializeObject<ExpandoObject>("JSON TEXT", new ExpandoObjectConverter());
And you can access the properties using dynamic input:
long someValue = response.@object.property _1.values.value;
In addition, since ExpandoObject implements IDictionary<string, object> , you can use it as a dictionary and check if the property exists:
if(((IDictionary<string, object>) response.@object ).ContainsKey("property_1")) { }
It seems that you are going to save a lot of time along the way!
Answer to this answer
It seems that most of the hate in my answer is focused on this @EZI comment:
And let you not know property_14 before json deserialization.
And another @LB responder claims this in his own answer:
But this approach will require you to know that property_14 will be returned by your server in advance ...
In my case, I believe this problem is already resolved in my answer when I mention that ExpandoObject implements IDictionary<string, object> . You may not know that property_14 will be part of a deserialized object graph. No problem :
if(((IDictionary<string, object>) response.@object ).ContainsKey("property_14")) {
source share