Dynamically parse nested JSon data to C# class

Is there a way to make to rewrite this dynamically?  There are over 500 "public inner" / "[JsonProperty(PropertyName =" in this Json data.

class Program
    {
        static string json = "{\"OBITS/BTS\":{\"timestamp\":1518205774653,\"asks\":[],\"bids\":[]},\"MSCN/RUR\":{\"timestamp\":1518205774654,\"asks\":[],\"bids\":[]}}";
        static void Main(string[] args)
        {
            var data = JsonConvert.DeserializeObject<Outer>(json);
            Console.WriteLine("OBITS/BTS - TimeStamp: {0}; Asks: {1}; Bids: {2}", data.ObitsBts.Timestamp, data.ObitsBts.Asks.Count, data.ObitsBts.Bids.Count);
            Console.WriteLine("MSCN/RUR - TimeStamp: {0}; Asks: {1}; Bids: {2}", data.MscnRur.Timestamp, data.MscnRur.Asks.Count, data.MscnRur.Bids.Count);
            Console.ReadLine();
        }
    }

    class Outer
    {
        [JsonProperty(PropertyName = "OBITS/BTS")]
        public Inner ObitsBts { get; set; }
        [JsonProperty(PropertyName = "MSCN/RUR")]
        public Inner MscnRur { get; set; }
    }

    class Inner
    {
        public BigInteger Timestamp { get; set; } 
        public List<int> Asks { get; set; }
        public List<int> Bids { get; set; }
    }

Open in new window

CAMPzxzxDeathzxzxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
No idea about your comfort level / expertise in C#.

Did you manage to have a look into dynamic keyword in C#? If not, please do.

It may take a while for me to write a sample code, so posting this just to give you a head-start.

Do let me know if further help is required. Also if you could post complex enough json to try with, please.
0
CAMPzxzxDeathzxzxAuthor Commented:
I'm comfortable with C# and SQL but not JSON.  I know that this data is not valid...
here is a snippet:

{"OBITS/BTS":{"timestamp":1518205774653,"asks":[],"bids":[]},"MSCN/RUR":{"timestamp":1518205774654,"asks":[],"bids":[]}

Open in new window


 so now I'm attempting this...


json = json.Substring(json.IndexOf("[") + 1);
json = json.Substring(0, json.LastIndexOf("]"));
var rootObjects = JsonConvert.DeserializeObject<RootObject>(json);

Open in new window

0
CAMPzxzxDeathzxzxAuthor Commented:
 HttpResponseMessage message = httpClient.GetAsync(uri).Result;

var inter = message.Content.ReadAsStringAsync();

string obj = JsonConvert.DeserializeObject(inter.Result).ToString();

Open in new window


Get's me this..

JSON visualizer
The original question shows a class structure that works..

class Outer
    {
        [JsonProperty(PropertyName = "OBITS/BTS")]
        public Inner ObitsBts { get; set; }
        [JsonProperty(PropertyName = "MSCN/RUR")]
        public Inner MscnRur { get; set; }
    }

    class Inner
    {
        public BigInteger Timestamp { get; set; } 
        public List<int> Asks { get; set; }
        public List<int> Bids { get; set; }
    }

Open in new window



But I'm looking to parse these dynamically.
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

CAMPzxzxDeathzxzxAuthor Commented:
I got it into a data form I can use!

HttpResponseMessage message = httpClient.GetAsync(uri).Result;

                    var inter = message.Content.ReadAsStringAsync();

                    string obj = JsonConvert.DeserializeObject(inter.Result).ToString();

                    var x = (JsonConvert.DeserializeObject<IDictionary<string, object>>(obj));

Open in new window

0
Nitin SontakkeDeveloperCommented:
Is it safe to assume that your problem is solved?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CAMPzxzxDeathzxzxAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.