"cast JObject to dictionary c#" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "cast JObject to dictionary c#" answered properly. Developers are finding an appropriate answer about cast JObject to dictionary c# related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like cast JObject to dictionary c#. Enter your desired code related query in the search bar and get every piece of information about C# code related question on cast JObject to dictionary c#. 

cast JObject to dictionary c#

By Clever CrossbillClever Crossbill on Nov 13, 2020
public static class JObjectExtensions
{
    public static IDictionary<string, object> ToDictionary(this JObject @object)
    {
        var result = @object.ToObject<Dictionary<string, object>>();

        var JObjectKeys = (from r in result
                           let key = r.Key
                           let value = r.Value
                           where value.GetType() == typeof(JObject)
                           select key).ToList();

        var JArrayKeys = (from r in result
                          let key = r.Key
                          let value = r.Value
                          where value.GetType() == typeof(JArray)
                          select key).ToList();

        JArrayKeys.ForEach(key => result[key] = ((JArray)result[key]).Values().Select(x => ((JValue)x).Value).ToArray());
        JObjectKeys.ForEach(key => result[key] = ToDictionary(result[key] as JObject));

        return result;
    }
}

Source: csharppedia.com

Add Comment

0

All those coders who are working on the C# based application and are stuck on cast JObject to dictionary c# can get a collection of related answers to their query. Programmers need to enter their query on cast JObject to dictionary c# related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about cast JObject to dictionary c# for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of cast JObject to dictionary c# while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "cast JObject to dictionary c#". Visit this developer's friendly online web community, CodeProZone, and get your queries like cast JObject to dictionary c# resolved professionally and stay updated to the latest C# updates. 

C# answers related to "cast JObject to dictionary c#"

View All C# queries

C# queries related to "cast JObject to dictionary c#"

Browse Other Code Languages

CodeProZone