C# - Partial deserializing JSON to .NET object using Newtonsoft

C# - Partial deserializing JSON to .NET object using Newtonsoft

C# JSON Newtonsoft

If you just need to get a few items from the JSON object, I would use Json.NET's LINQ to JSON JObject class.

=== For example:

JToken token = JObject.Parse(stringFullOfJson);

int page = (int)token.SelectToken("page");
int totalPages = (int)token.SelectToken("total_pages");

I like this approach because you don't need to fully deserialize the JSON object. This comes in handy with APIs that can sometimes surprise you with missing object properties, like Twitter.

Source

StackOverflow - https://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe/4749755#4749755

Archive - https://archive.ph/qJNMo

Previous Post Next Post